2

I am working with website built with Facebook React JS Library. I want to test if a input form is populated with a text or to use it in unittest method. I tried this but this does not work at all. Problem is my given input data is not in the that DOM even not the page source.

In this case how to check if input-form is filled?

demo

Community
  • 1
  • 1
Learner
  • 5,192
  • 1
  • 24
  • 36

1 Answers1

2

Locate the input element and get the value attribute:

district = driver.find_element_by_css_selector("input[label=District]")
print(district.get_attribute("value"))

You might also need to wait for that element to become visible first:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
district = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[label=District]")))
print(district.get_attribute("value"))
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 1
    @SIslam sure, it's just that this is an `input` element and the value you see in the input is held inside the `value` attribute and not the element's text.. – alecxe Mar 25 '16 at 13:53