0

I have a test cases written in python selenium and when I try to get the text from a web element, it fails. I tried the following before get text on that web element to check if the code identifies the element but still fails

  1. Find if element in the page(this line pass in the test case). It identifies that element and but fails to get the text
  2. Find if element is visible (this line pass in the test case) - It identifies that element is visible and but fails to get the text
  3. Find if element is enabled (this line pass in the test case) -It identifies that element is enabled and but fails to get the text

If I do sleep of 1 second. Then the text is extracted from the element. I don't want to give this sleep in my test case. Please tell me why it fails and what can i do other that sleep to get this element.

note -silmiarly i have drop down element for which the same happens.

please advise

1 Answer 1

2

It seem that text is generated dynamically so you need to wait until target element contains any text:

from selenium.webdriver.support.ui import WebDriverWait as wait

element = driver.find_element_by_xpath("//node")
text_content = wait(driver, 10).until(lambda driver: element.text)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.