无法在gmail中找到密码字段。忘记错误" webdriver exception"

时间:2018-05-28 10:07:06

标签: selenium-webdriver

    import java.util.concurrent.TimeUnit;
    import org.testng.annotations.*;
    import static org.testng.Assert.*;
    import org.openqa.selenium.*;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class Withtestng {
      private WebDriver driver;

      private boolean acceptNextAlert = true;
      private StringBuffer verificationErrors = new StringBuffer();

      @BeforeClass(alwaysRun = true)
      public void setUp() throws Exception {
         System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
         System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }

      @Test
      public void testGmailLogInHtml() throws Exception {
        driver.get("https://www.google.com/");
        driver.findElement(By.linkText("Gmail")).click();
        driver.findElement(By.xpath("/html/body/nav/div/a[2]")).click();
        driver.findElement(By.id("identifierId")).click();
        driver.findElement(By.id("identifierId")).clear();
        driver.findElement(By.id("identifierId")).sendKeys("xyz@gmail.com");


 driver.findElement(By.xpath("//div[@id='identifierNext']/content")).click();

driver.findElement(By.xpath("//input[@class='whsOnd zHQkBf']")).click();
driver.findElement(By.xpath("//input[@class='whsOnd zHQkBf']")).clear();
driver.findElement(By.xpath("//input[@class='whsOndzHQkBf']")).sendKeys("xyz");***
            driver.findElement(By.xpath("//div[@id='passwordNext']/content/span"))click();
            driver.findElement(By.xpath("//div[@id='gb']/div/div/div[2]/div[5]/div/a/span")).click();
driver.findElement(By.id("gb_71")).click();
          }

1 个答案:

答案 0 :(得分:0)

您的脚本执行速度和页面加载时间不同步,请尝试使用 pageLoadTimeout。

driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);//

您可以等待特定条件变为真(即,使用wait.until等到元素存在为止),然后对其执行操作。