1

While entering only username no problem is occurred. But, if i write code to enter both username & password another page is coming.

ex.

obj.findElement(By.name("username")).sendKeys("xxxxx"); //no problem required page coming and entering username.
if i write two 
ex.  obj.findElement(By.name("username")).sendKeys("xxxxx");
     obj.findElement(By.name("password")).sendKeys("xxxxx");// different page coming unable to enter username and password.
4
  • Are you using the new gmail.com login? I would also be curious what the actual error message you're seeing is.
    – Swagin9
    May 1, 2017 at 15:10
  • it is unable to find password element because page is changing as i told May 1, 2017 at 15:36
  • Here the main question will be which Gmail login are you referring, the older login page or the newly implemented login page? May 1, 2017 at 19:30
  • Agree with Swagin9 You will want to add a wait step to wait for the password field to be visible before trying to send the value
    – Nick
    May 2, 2017 at 1:27

3 Answers 3

1

As per my understanding problem with gmail is: It have 2 pages for login.

  1. User Name
  2. Password

So steps should be:

  1. Enter user name
  2. click on Next
  3. Enter password.
  4. Click on signin.

Sharing the sample code. Just remember google have change their page. So giving both code which work on new page as well as on old page.

driver.get("http://www.gmail.com");
// **** checking if url is of new then use if code otherwise else code.
if(driver.getCurrentUrl().contains("https://accounts.google.com/signin/v2/identifier?")){
        driver.findElement(By.id("identifierId")).sendKeys("xxxxxxxx");
        driver.findElement(By.id("identifierNext")).click();

        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password"))); 
        driver.findElement(By.name("password")).sendKeys("xxxxxxxx");
        driver.findElement(By.id("passwordNext")).click();
    }
    else{
        driver.findElement(By.name("Email")).sendKeys("xxxxxxxxx");
        driver.findElement(By.id("next")).click();
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Passwd")));
        driver.findElement(By.name("Passwd")).sendKeys("xxxxxx");
        driver.findElement(By.name("signIn")).click();
    }

I hope it will help you. Please ignore the multiple creation of wait object. Just provide the snippet.

13
  • . your thought is really excellent but unable to enter password in the both situations . how can i enter ? (i tried with wait object and without wait object unable to enter) May 2, 2017 at 11:39
  • i mean in the if block and else block in both the situations am unable to enter password. thanks May 2, 2017 at 12:29
  • Few questions: 1. Are you able to move to next screen (password screen) 2. If possible share exception and your code? 3. Can you share the Google login page screenshots? May 2, 2017 at 14:27
  • 1
    I was able to do login using above code. Freshly tried then share over here. May 2, 2017 at 14:30
  • Are you able to login now? May 3, 2017 at 11:25
1

You will want to add a wait step to wait for the password field to be visible before trying to send the value

2
  • page is changing and unable to locate password element. read my question once again. May 1, 2017 at 16:00
  • 2
    Yes, I understand that, which is why you need to add a wait step to wait for the page to stop changing before you try to send the password value.
    – Swagin9
    May 1, 2017 at 16:29
0

Normally something like this should do the job :

driver.get(link)

# find email, send data and submit
EMAIL_FIELD = driver.find_element_by_id('identifierId')
EMAIL_FIELD.click()
EMAIL_FIELD.clear()
EMAIL_FIELD.send_keys(Email)
EMAIL_FIELD.send_keys(Keys.ENTER)
time.sleep(3)
driver.get_screenshot_as_file('1_email_input.png')


driver.find_element_by_xpath(".//*[@id='identifierNext']/content/span").submit()
time.sleep(3)
driver.get_screenshot_as_file('2_input_entered.png')

# find password, send data and submit
PASSWD_FIELD = driver.find_element_by_id('password')
PASSWD_FIELD.click()
PASSWD_FIELD.clear()
PASSWD_FIELD.send_keys(Passwd)
PASSWD_FIELD.send_keys(Keys.ENTER)
time.sleep(3)
driver.get_screenshot_as_file('3_password_input.png')

driver.find_element_by_xpath(".//*[@id='identifierNext']/content/span").submit()
time.sleep(3)
driver.get_screenshot_as_file('4_password_entered.png')

# get cookies
cookies = driver.get_cookies()

But at the moment I also can't get it working, very odd, the email is not actually posted anymore. Not like this and not with send_keys(Keys.ENTER) on the email field itself.

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