gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:30:17 25 4
gpt4 key购买 nike

公共(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com