我正在尝试使用 Selenium 来自动化某些 Web 浏览。目前我正在尝试按类名访问特定元素并返回其中的文本(我在页面上选择的元素肯定有文本)当我尝试在我的函数中返回它时我得到
TypeError: 'unicode' object is not callable
我的函数代码如下:
driver = webdriver.Chrome("my chromedriver installation path")
driver.get("website URL")
def getText():
return driver.find_element_by_class_name("class with text").text()
print getText()
最佳答案
.text
不是方法,它是属性:
driver.find_element_by_class_name("class with text").text
关于Python Selenium 返回文本,unicode 对象不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30943314/