1

I've been trying to fill input:

<input id="PASSFIELD1" class="logField" type="password" onkeyup="next(this, event);" maxlength="1" autocomplete="off" name="PASSFIELD1"></input>

To do this, I have to find this element.

I tried below things:

1. pass1=driver.find_element_by_name("PASSFIELD1")

2. pass1=driver.find_element_by_id("PASSFIELD1")
3. pass1= driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/form/div[3]/table/tbody/tr[3]/td[2]/div/input[1]") (path from firebug)
  1. Even wait 100 seconds for it
self.wait.until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[4]/div/div/div[2]/div/form/div[3]/table/tbody/tr[3]/td[2]/div/input[1]")))

self.assertTrue(self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/form/div[3]/table/tbody/tr[3]/td[2]/div/input[1]"))
selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate element: (...)

Do you know what I am doing wrong?

1
  • 1
    Look more into the DOM - is there an iframe? Is it shadow DOM? – pavelsaman Jan 27 at 10:53
1

You should wait for an element before trying to interact with it. There are generally two options and do not mix use of the two.

  1. Use implicit waits
from selenium import webdriver

driver = webdriver.Firefox()
driver.implicitly_wait(10) # seconds
driver.get("http://somedomain/url_that_delays_loading")
myDynamicElement = driver.find_element_by_id("myDynamicElement")
  1. Use explicit waits
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'someid')))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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