How can I wait for a presence of an element which the content (text) is not empty? I tried select by xpath using //*[@id="test" and text() != ""]
, but the return of WebDriverWait#until
does not retrieve the element.
My code:
selector = '//*[@id="test" and text() != ""]'
element = WebDriverWait(driver, timeout).until(
expected_conditions.presence_of_element_located((By.XPATH, selector))
)
I would like to get the text content of the element. I tried:
print element.text # prints 0
If i print only element
, the output is <selenium.webdriver.remote.webelement.WebElement(session="xxx", element="xxx")>
. What is wrong?
The div I'm tryin to get has this structure:
<div>
Test:
<div id="test"><b>this text here</b></div>
</div>
You can wait for an element by xpath with non empty text like this:
xpath = "//*[@id='test']"
WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_xpath(xpath).text.strip() != '')
source
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