Python Selenium 返回文本,Unicode对象不可调用。

5

我正在尝试使用Selenium自动化一些网络浏览。目前,我正在尝试通过类名访问特定元素并返回其中的文本(我在页面上选择的元素中肯定有文本),但是当我尝试在我的函数中返回它时,出现了问题。

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()
1个回答

9

.text并不是一个方法,而是一个属性:

driver.find_element_by_class_name("class with text").text

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接