Selenium get_attribute()方法獲取列表元素信息

text()方法可以獲取單個元素的鏈接文本

如果想要列表裏的全部元素的鏈接文本,可以使用get_attribute()方法

使用方法:

list = dr.find_elements_by_xpath("//*[@id='user-table']//tbody/tr[1]//ul/li/a") 
for i in list:
    print(i.get_attribute("textContent").strip())

get_attribute()還有get_attribute("innerHTML") 和get_attribute("outerHTML")方法

實踐得出,get_attribute("textContent")和get_attribute("innerHTML")可獲得鏈接文本

get_attribute("outerHTML")可獲得a鏈接全部信息,如下圖標出的 <a href="#modal" data-toggle="modal" data-url="/admin/user/2964/avatar">修改用戶頭像</a>

 

另外,對 a 標籤中的每個屬性進行 get_attribute 操作獲取,如

element.get_attribute("class")

element.get_attribute("href")

elemnet.get_attribute("date-url")

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章