java - 无法在Java中使用selenium webdriver自动登录Gmail

标签 java selenium webdriver gmail autologin

公共(public)类自动电子邮件{ public static 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();
}

}

最佳答案

引用自 support.google.com :

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

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

关于java - 无法在Java中使用selenium webdriver自动登录Gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59960081/

相关文章:

java - 如何返回延迟实例化的动态网络元素

java - 签名长度不正确

java.lang.reflect.InitationTargetException 错误

java - Vertx 运行多个事件循环

java - Selenium 中的页面加载超时

python - Selenium-ChromeDriver SSL 错误/握手失败

javascript - 通过 Selenium Webdriver 验证 JavaScript 错误

java - WebElement.findElement 未找到子元素

java - 从 tomcat 服务器中的 webapp 调用 java 程序 - java 程序在 tomcat 服务器之外

java - 提取具有相同类名的表数据