首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gmail - Web驱动程序自动化

Gmail - Web驱动程序自动化
EN

Stack Overflow用户
提问于 2017-01-10 12:13:30
回答 2查看 1.1K关注 0票数 0

这是我试图通过Web驱动自动化Gmail的代码。

我发现了一些奇怪的东西。每当我注释掉这行以查找Password (Driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("SRS");)

则Web Driver成功地点击了"Sign In“按钮

但当我取消注释这行代码时

代码语言:javascript
复制
(Driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("SRS");) 

则Web Driver也不能单击登录按钮,并且它会给出错误消息,即Unable to find the Password Xpath仍然只显示在电子邮件id屏幕上。

Here is the attached屏幕截图

代码语言:javascript
复制
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver Driver = new FirefoxDriver();
        Driver.get("https://www.google.com/gmail/about/");
        Driver.findElement(By.xpath("html/body/nav/div/a[2]")).click();
        Driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        //Enter the Gmail ID
        Driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("RK12@gmail.com");
        Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        //Click on Next Button
        Driver.findElement(By.xpath(".//*[@id='next']")).click();
        Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);


        Driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("SRS");
        //Driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);


    }

}
EN

回答 2

Stack Overflow用户

发布于 2017-01-10 15:55:43

1.你给出了错误的电子邮件id,因此谷歌对其进行了验证,并显示错误消息为“对不起,谷歌无法识别该电子邮件”。

因此,请输入有效的电子邮件id才能进入密码页面。

2.这里的与问题中的代码一起提供了ElementNotVisibleException,因此添加了ExpectedConditions.visibilityOfElementLocated,以确保在发送密钥之前加载了密码字段。

更新代码:

代码语言:javascript
复制
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail {

   public static void main(String[] args) {

        WebDriver Driver = new FirefoxDriver();
        Driver.get("https://www.google.com/gmail/about/");
        Driver.findElement(By.xpath("html/body/nav/div/a[2]")).click();
        Driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        //Enter the Gmail ID
        Driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("rbnaveen558@gmail.com");
        Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        //Click on Next Button
        Driver.findElement(By.xpath(".//*[@id='next']")).click();
        Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        WebDriverWait wait = new WebDriverWait(Driver, 10);
        WebElement pwd = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
        pwd.sendKeys("SRS");
        //Driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
   }
}
票数 0
EN

Stack Overflow用户

发布于 2017-01-10 16:25:20

请添加“登录”按钮,我测试的this.This是正常的。driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("SRS"); driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS); //click to sign in driver.findElement(By.id("signIn")).click();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41561025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档