0

Problem : element.text is not working and continuously returning empty even when I can see a real value

Solutions I have tried :

  1. Tried finding element using different locator strategy: like xpath, class_name, css_selector, id & even combination of two locators adv strategy too
  2. I have ensure page got loaded & ready, element is displayed, added condition with wait until element get clickable etc

Team, Let me know if you have faced and applied working solution for this issue. Thanks!

System :

  • Python
  • Selenium
  • Edge browser & Chrome
  • Target : any browser

1 Answer 1

0

Working solution:

  • Element is normal text field: element.text
    element = context.driver.find_element_by_xpath('//*[@id="element-id"]')
    print("element.text >>> >>> >>> ", element.text)
  • Element is input field:input_element.get_attribute("value")
    WebDriverWait(context.driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#element-id")))
    input_element = context.driver.find_element_by_xpath('//*[@id="element-id"]')
    getTextVal = input_element.get_attribute("value")
    print("element.text >>> >>> >>> ", getTextVal)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.