0

I am trying to login to Google with selenium. The steps are simple, first you type email and hit next, then you type password and hit next. My code looks like this:

driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)

The first part of code (email part) works perfectly. I also checked the last part (hitting next after the password is written) and it also works great. The only problem is with password. when I try to do password.send_keys("password") it causes the following error:

TypeError: object of type 'FirefoxWebElement' has no len()

Any suggestions on what to do?

Giorgi Cercvadze
  • 403
  • 1
  • 7
  • 23

1 Answers1

2

The problem was, I just had to wait for passwords pressence and visibility to be loaded, like this:

driver = webdriver.Firefox()
driver.get("https://accounts.google.com/signin")

driver.implicitly_wait(3)

driver.find_element_by_id("identifierId").send_keys("email")
driver.find_element_by_id("identifierNext").click()

driver.implicitly_wait(8)
password = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@type='password']")))
password = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@type='password']")))

password = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")
password.send_keys("password")

element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
Giorgi Cercvadze
  • 403
  • 1
  • 7
  • 23