公共(public)类自动电子邮件{ public static void main(String[] args) 抛出 InterruptedException、FileNotFoundException、IOException、ParseException {
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 可能会停止通过以下浏览器登录:
- 不支持 JavaScript 或已关闭 JavaScript。
- 添加了不安全或不受支持的扩展程序。
- 使用自动化测试框架。
- 嵌入到不同的应用程序中。
关于java - 无法在Java中使用selenium webdriver自动登录Gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59960081/