Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium return text, unicode object is not callable

I'm trying to use Selenium to automate some web browsing. Currently I'm trying to access a specific element by class name and return the text within it (the element im selecting on the page definetly has text in it) and when I try to return it in my function I get

TypeError: 'unicode' object is not callable

My code for the function is as follows:

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()
like image 643
Adam Griffiths Avatar asked Jun 19 '15 16:06

Adam Griffiths


1 Answers

.text is not a method, it is an attribute:

driver.find_element_by_class_name("class with text").text
like image 58
alecxe Avatar answered Nov 03 '22 11:11

alecxe