Adam Griffiths
Adam Griffiths

Reputation: 792

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()

Upvotes: 5

Views: 4925

Answers (1)

alecxe
alecxe

Reputation: 473873

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

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

Upvotes: 9

Related Questions