-3

having trouble with my python code. I keep getting python no such element: unable to locate element {"method": "id","selector":"email"}

my code:

self.driver.get(redirecturl)

email = "testmail02015@
Password = "Passw0rd123"
emailFieldID = "email"
passwordFieldID = "password"
loginButtonXpath = "//button[@value='btnLogin']"

self.driver.find_element_by_id(emailFieldID).send_keys(email)
self.driver.find_element_by_id(passwordFieldID).send_keys(Password)
self.driver.find_element_by_xpath(loginButtonXpath).click()
Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
Tony sanchez
  • 85
  • 1
  • 2
  • 9

1 Answers1

3

Usually the problem is that find_element runs too quickly before page fully loaded. So try to wait for elements to appear (in the example it waits for maximum of 10 seconds; less if element appears earlier):

...
emailFieldID = "email"
...

WebDriverWait(browser, 10).until(EC.presence_of_element_located(browser.find_element_by_id(emailFieldID)))

self.driver.find_element_by_id(emailFieldID).send_keys(email)

After that you can use find_element as usual.

timbre timbre
  • 12,648
  • 10
  • 46
  • 77