I am beginner in selenium webdriver and I am trying to login gmail account through xpath, now problem is that I have found an xpath for email and in these send a key. When we run the report the key sent to the password field instead of email, please help me how to resolve it. Here is my code:
我是selenium webdriver的初学者,我试图通过xpath登录gmail帐户,现在问题是我找到了一个电子邮件的xpath,并在这些中发送密钥。当我们运行报告时,密钥发送到密码字段而不是电子邮件,请帮我解决问题。这是我的代码:
public class Usingxpath {
static boolean c,c1,c2;
public static void main(String[] args) throws Exception
{
// TODO Auto-generated method stub
WebDriver wD = new FirefoxDriver();
wD.get("https://www.gmail.com/");
Thread.sleep(2000);
c=wD.findElement(By.xpath("/html/body/div/div[2]/div[2]")).isDisplayed();
if(c==true){
System.out.println("SignIn board is present");
}
c1=wD.findElement(By.xpath("/html/body/div/div[2]/div[2]/form")).isDisplayed();
if(c1==true){
System.out.println("Form is present");
}
c2=wD.findElement(By.xpath("/html/body/div/div[2]/div[2]/form/input[15]")).isDisplayed();
if(c1==true){
System.out.println("email field is present");
}
WebElement emailInput= wD.findElement(By.xpath("/html/body/div/div[2]/div[2]/form/input[15]"));
emailInput.clear();
emailInput.sendKeys("xyz@gmail.com");
wD.quit();
}
1 个解决方案
#1
0
Don't use absolute xpathes. If you use some xpath browser plugin like Firepath for Firefox disable absolute xpath generating.
不要使用绝对xpathes。如果您使用某些xpath浏览器插件,如Firepath for Firefox禁用绝对xpath生成。
So your xpathes can be look like this:
所以你的xpathes可以是这样的:
-
//form[@id='gaia_loginform']//input[@id='Email'] - for email input
// form [@ id ='gaia_loginform'] //输入[@ id ='电子邮件'] - 用于电子邮件输入
-
//form[@id='gaia_loginform']//input[@id='Passwd'] - for password input
// form [@ id ='gaia_loginform'] //输入[@ id ='Passwd'] - 输入密码
#1
0
Don't use absolute xpathes. If you use some xpath browser plugin like Firepath for Firefox disable absolute xpath generating.
不要使用绝对xpathes。如果您使用某些xpath浏览器插件,如Firepath for Firefox禁用绝对xpath生成。
So your xpathes can be look like this:
所以你的xpathes可以是这样的:
-
//form[@id='gaia_loginform']//input[@id='Email'] - for email input
// form [@ id ='gaia_loginform'] //输入[@ id ='电子邮件'] - 用于电子邮件输入
-
//form[@id='gaia_loginform']//input[@id='Passwd'] - for password input
// form [@ id ='gaia_loginform'] //输入[@ id ='Passwd'] - 输入密码