I try to log in to Google with Selenium. It works if I use sleep() like this code:
browser = webdriver.Firefox()
browser.get('https://admin.google.com/')
emailElem = browser.find_element_by_id('Email')
emailElem.send_keys('mymail')
nextButton = browser.find_element_by_id('next')
nextButton.click()
sleep(5)
passwordElem = browser.find_element_by_id('Passwd')
passwordElem.send_keys('mypass')
signinButton = browser.find_element_by_id('signIn')
signinButton.click()
If I change sleep to WebDriverWait like this
browser = webdriver.Firefox()
browser.get('https://admin.google.com/')
emailElem = browser.find_element_by_id('Email')
emailElem.send_keys('mymail')
nextButton = browser.find_element_by_id('next')
nextButton.click()
passwordElem = WebDriverWait(browser, 5).until(
EC.presence_of_element_located(browser.find_element_by_id('Passwd'))
)
passwordElem.send_keys('mypass')
signinButton = browser.find_element_by_id('signIn')
signinButton.click()
It shows an error like this:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="Passwd"]
How can I use WebDriverWait?
NoSuchElementException. In case ofWebdriverWait+ExpectedConditionsyou should getTimeOutException! Are you sure that you show us correct code?