Unable to locate password field in gmail login page | Selenium Forum
M
Posted on 13/01/2016
unable to locate password field in gmail login page.
Have commented series of xpath s i tried in code:
Am unable to locate password field.
Please refer snapshots for screens in my browser
Following is my code:
--------------------------------------------------
package p1;


import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Login_verifyy_gmail {
@Test(dataProvider = "dp")
public void f(String n, String s) {

WebDriver w=new FirefoxDriver();
w.get("http://www.gmail.com/");
w.findElement(By.xpath("//*[@id='Email']")).sendKeys(n);
w.findElement(By.xpath("//*[@id='next']")).click();
w.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

int size = w.findElements(By.tagName("iframe")).size();
System.out.println("Total frames in page- "+size);
w.switchTo().frame(0);
//w.findElement(By.xpath("//*[@id='Passwd']"));
//w.findElement(By.name("Passwd")).sendKeys(s);
//w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(s);

//w.findElement(By.xpath("//div[@id='password-shown']/div/input")).sendKeys(s);

w.findElement(By.xpath("html/body/div[1]/div[2]/div[2]/div[1]/form/div[2]/div/div[2]/div/div/input[2]")).sendKeys(s);
//w.findElement(By.xpath("html/body/div[1]/div[2]/div[2]/div[1]/form/div[2]/div/div[2]/div/div/input[2]")).sendKeys(Keys.ENTER);
//w.findElement(By.xpath("//div[@id='password-shown']/div/input")).sendKeys(Keys.ENTER);
//"
//c.sendKeys(s);
//driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(password);

System.out.println("n"+n+"s"+s);

}

@DataProvider
public Object[][] dp() {
/* return new Object[][] {
new Object[] { 1, "a" },
new Object[] { 2, "b" },*/


Object[][] x=new Object[1][2];
Xls_Reader x1=new Xls_Reader("C:\\Users\\chaitra\\Pictures\\shopping_cart.xlsx");
for(int i=0;i<1;i++)
{
x[i][i]=x1.getCellData("Login","Login_name",2);
x[i][1]=x1.getCellData("Login","pwd",2);
System.out.println("loginName"+x[i][i]+"loginName"+x[i][1]);
}
return x;



};
}

M
Replied on 13/01/2016

there are no iframe.

xpath for gmail password is [quote:1r84tshr].//*[@id='Passwd'][/quote:1r84tshr].

use that and get rid of all frame code.


M
Replied on 16/01/2016

sir,
Following is my code:
Issue is still d same.
--------------------
package p1;


import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Login_verifyy_gmail {
@Test(dataProvider = "dp")
public void f(String n, String s) {

WebDriver w=new FirefoxDriver();
w.get("http://www.gmail.com/");
w.findElement(By.xpath("//*[@id='Email']")).sendKeys(n);
w.findElement(By.xpath("//*[@id='next']")).click();
w.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(s);//====>Unable to locate element: {"method":"xpath","selector":"//*[@id='Passwd']"}
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(Keys.ENTER);


System.out.println("n"+n+"s"+s);

}

@DataProvider
public Object[][] dp() {
/* return new Object[][] {
new Object[] { 1, "a" },
new Object[] { 2, "b" },*/


Object[][] x=new Object[1][2];
Xls_Reader x1=new Xls_Reader("C:\\Users\\chaitra\\Pictures\\shopping_cart.xlsx");
for(int i=0;i<1;i++)
{
x[i][i]=x1.getCellData("Login","Login_name",2);
x[i][1]=x1.getCellData("Login","pwd",2);
System.out.println("loginName"+x[i][i]+"loginName"+x[i][1]);
}
return x;



};
}


M
Replied on 17/01/2016

WebDriver w=new FirefoxDriver();
w.get("http://www.gmail.com/");
w.findElement(By.xpath("//*[@id='Email']")).sendKeys(n);
w.findElement(By.xpath("//*[@id='next']")).click();
thread.sleep(5000)
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(s);//====>Unable to locate element: {"method":"xpath","selector":"//*[@id='Passwd']"}
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(Keys.ENTER);