无法使用Java中的Selenium WebDriver自动登录Gmail

时间:2020-01-29 03:23:09

标签: java selenium webdriver gmail autologin

公共类AutoEmail { 公共静态void main(String [] args)抛出InterruptedException,FileNotFoundException,IOException,ParseException {enter image description here

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\try\\Documents\\NetBeansProjects\\AutoEmail\\chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.setExperimentalOption("useAutomationExtension", false);
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    WebDriver driver =  new ChromeDriver(options); 

    driver.get("https://accounts.google.com/ServiceLogin?");

    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("email@gmail.com");
    driver.findElement(By.id("identifierNext")).click();

    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("password");
    driver.findElement(By.id("passwordNext")).click();
}

}

1 个答案:

答案 0 :(得分:3)

来自support.google.com的引用:

为保护您的帐户,Google不允许您使用某些浏览器登录。 Google可能会停止从以下浏览器登录:

  1. 不支持JavaScript或关闭Javascript。
  2. 已添加了不安全或不受支持的扩展名。
  3. 使用自动化测试框架。
  4. 嵌入到其他应用程序中。
相关问题