What's the get_Text() equivalent in python bindings for Selenium/Webdriver
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 ?
use the '.text' property.
element.text
This line of code...
selenium.find_elements_by_css_selector("locator").get_text()
...have exactly two (2) issues to be addressed.
Details
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*
Solution
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")
精彩评论