Reputation: 83
I would like to move from Selenium 1 to Selenium 2. I use python binding however I can not find any get_text()
functions.
eg. selenium.find_elements_by_css_selector("locator").get_text()
Is there such function in python bindings for Selenium/Webdriver ?
Upvotes: 5
Views: 6729
Reputation: 193298
This line of code...
selenium.find_elements_by_css_selector("locator").get_text()
...have exactly two (2) issues to be addressed.
As per the current documentation get_Text()
can be implemented in two different approaches:
Using the text attribute: Gets the text of the element.
Using the get_attribute("innerHTML")
: Gets the innerHTML of the element.
Additionally, text attribute or get_attribute("innerHTML")
can be applied on a WebElement but not on WebElements. Hence find_elements*
needs to be replaced with find_element*
Effectively, your line of code will be:
Using text attribute:
selenium.find_element_by_css_selector("locator").text
Using get_attribute("innerHTML")
:
selenium.find_element_by_css_selector("locator").get_attribute("innerHTML")
Upvotes: 0