【问题标题】:Email is not taken or not sending a key through xpath电子邮件未通过或未通过 xpath 发送密钥
【发布时间】:2014-07-27 11:45:07
【问题描述】:

我是 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();

}

【问题讨论】:

    标签: email selenium xpath selenium-webdriver


    【解决方案1】:

    不要使用绝对 xpath。如果您使用某些 xpath 浏览器插件,例如 Firepath for Firefox,请禁用绝对 xpath 生成。

    所以你的 xpath 可以是这样的:

    1. //form[@id='gaia_loginform']//input[@id='Email'] - 用于电子邮件输入

    2. //form[@id='gaia_loginform']//input[@id='Passwd'] - 用于密码输入

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2011-12-19
      • 2017-06-05
      • 2015-07-12
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多