0

I am trying to log in to my gmail account via Selenium on Python and the problem is: I can enter the username correctly, but nothing is entered into the password section

To put in context, for Gmail, you have to put your username in, then move on to the password section after. I have attempted to do the following solutions: - refreshing the page in between entering username and pword (this causes you to go to some other screen) - waiting for the password box to appear (didn't make any change) - trying to access the box by id instead of xpath (didn't work)

Here is my code below:

from selenium import webdriver
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC

keys = {
    'url':'http://www.gmail.com',
    'username':'xxxxxxxxxxxx',
    'pword':'xxxxxxxxxxxx',
    'email':'xxxxxxxxxxxx',
    'title':'xxxxxxxxxxxx',
    'text':'xxxxxxxxxxxxxx'
}

driver = webdriver.Safari()
driver.get(keys['url'])
driver.find_element_by_xpath('//*[@id="identifierId"]').click()
driver.find_element_by_xpath('//*[@id="identifierId"]').send_keys(keys['username'])
driver.find_element_by_xpath('//*[@id="identifierNext"]/content/span').click()

# wait for the password field to be visible
#wait = WebDriverWait(browser, 10)
#passwordElem = wait.until(EC.visibility_of_element_located((By.ID, "Passwd")))
#passwordElem.clear()

driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys(keys['pword'])
driver.find_element_by_xpath('//*[@id="passwordNext"]/content').click()

The commented sections are the edits I attempted to make.

Any help would be greatly appreciated. Thanks in advance.

Ninja_star
  • 57
  • 1
  • 5

1 Answers1

0

add sleep after clicking next button

....
driver.find_element_by_xpath('//*[@id="identifierNext"]/content/span').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys(keys['pword'])
driver.find_element_by_xpath('//*[@id="passwordNext"]/content').click()

or using WebDriverWait

driver.find_element_by_xpath('//*[@id="identifierNext"]/content/span').click()

# wait for the password field to be visible
wait = WebDriverWait(driver, 10) # not "browser"
passwordElem = wait.until(EC.visibility_of_element_located((By.NAME, "password"))) # not By.ID
passwordElem.send_keys(keys['pword'])
driver.find_element_by_xpath('//*[@id="passwordNext"]/content').click()
ewwink
  • 18,382
  • 2
  • 44
  • 54
  • Thanks for your response. I have made the edits that you have posted, but it still just does nothing at the password screen. I wonder if perhaps they have made the website such that it cannot be accessed by program (at least in this fashion) – Ninja_star Dec 08 '18 at 17:49
  • I made change for using `WebDriverWait` try it. – ewwink Dec 08 '18 at 17:57