Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python and how to get text from Selenium element WebElement object?

I am trying to get the tag text content in html page by using Selenium methods, but it seems method someElement.getText() is not available in Python. Any help, please?

Here's traceback:

AttributeError: 'WebElement' object has no attribute 'getText' 
like image 559
Alex Avatar asked Jan 19 '15 10:01

Alex


People also ask

How do you getText from an element in Selenium?

getText() Method in Selenium This method helps retrieve the text, which is basically the innertext of a WebElement. getText() method returns string as a result. It removes the whitespaces if present in the front and back of the string.

How can we get a text of WebElement?

We can get the text from a website using Selenium webdriver USING the getText method. It helps to obtain the text for a particular element which is visible or the inner text (which is not concealed from the page).

How do I find an element that contains specific text in Selenium Webdriver Python?

We can find an element that contains specific text with Selenium webdriver in Python using the xpath. This locator has functions that help to verify a specific text contained within an element. The function text() in xpath is used to locate a webelement depending on the text visible on the page.


1 Answers

Once you locate the element you can use the text property.

Example:

for element in self.driver.find_elements_by_tag_name('img'):        print element.text        print element.tag_name        print element.parent        print element.location        print element.size 
like image 190
aberna Avatar answered Oct 07 '22 16:10

aberna