【发布时间】:2020-11-07 10:54:24
【问题描述】:
getphone = driver.find_element_by_class_name('_3ko75')[-1]
phone = getphone.get_attribute("title")
不工作我需要获取字符串格式的标题。
Exception has occurred: TypeError
'WebElement' object is not subscriptable
File "C:\Users\vmaiha\Documents\Python Projects\Project 01\WP_Answer.py", line 43, in check
getphone = driver.find_element_by_class_name('_3ko75')[-1]
【问题讨论】:
-
@andrea 仍然无法正常工作:getphone = driver.find_element_by_class_name('_3ko75')[-1] phone = getphone.get_attribute("title")
-
我只是编辑了您的问题,以便更好地组织代码。我没有提供任何答案
-
谢谢安德烈
-
find_element 只返回一个 WebElement 对象。为什么最后使用 [-1]?
标签: python selenium selenium-webdriver xpath getattribute