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'
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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With