aleetesting
aleetesting

Reputation: 83

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 ?

Upvotes: 5

Views: 6729

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193298

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:

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

Upvotes: 0

Corey Goldberg
Corey Goldberg

Reputation: 60634

use the '.text' property.

element.text

Upvotes: 10

Related Questions