How to get text from an element with selenium

Omar Yacop

I am trying to get text from an element and then searching for it in another place, the problem is that when I get the text using .text, I noticed that it misses if there is two spaces, and when it searches in the next page, it can't find it. So is there a way to get text as it is with spaces?

Code:

self.name = session.find_element('xpath', './/a[contains(@href, "name")]').text
self.dataBrowser.find_elements(By.XPATH, f'//tr[child::td[child::div[child::strong[text()="{self.name}"]]]]')
Tal Angel

Not always the text property will actually hold the text. So, try this:

element = browser.find_element(By.CSS, 'CSS_EXPRESSION')
text = element.get_attribute('text')
if text is None or text is '':
    text = element.get_attribute('value')

If text and value both returns nothing just try reading the innnerHTML attribute.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Selenium - How to get the text from an element but retaining child element source

Selenium how to get text element

How to get text of an element in Selenium?

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

How to get element(text) from a table using Selenium WebDriver with Python

How to get the text from mouseover popup element using Selenium Webdriver

Python selenium get text from href element

Unable to get text from input element in selenium

Selenium can't get the text from element

python selenium get text from element

Get text from html element using selenium

How to get text from parent element and exclude text from children (C# Selenium)

How to select element with selenium in python and get the text?

Selenium JS how to get text of an element

How to get text of td element using selenium?

How to get text element in html head by selenium?

Python, Selenium: How to get text next to element

How to use selenium get Text from an element not including it's sub-element

Can't get text from element in selenium from outside tag?

How to get attribute of element from Selenium?

Python Selenium: How to get the innerHTML from element

How to get the actual text from a span element enclosed within multiple span tags, using Selenium Webdriver with Java

how to get Table element from a Div that has a Heading tag with a known text - using selenium and java

How to get text from web element where didn't have unic id or class in selenium java

How to get text from the tag with Selenium and BeautifulSoup

get text from element with <br> on its composition, using Python Selenium

Unable to get text from html element for Selenium Java

Cannot get text of element with Selenium

How to get element from another element selenium using WebDriverWait?