我正在自动化 Web 应用程序以在 Headless Chrome 中运行。
ChromeDriver 版本:- ChromeDriver 74.0.3729.6
应用程序登录屏幕会弹出窗口以输入用户名和密码。我使用警报来处理普通 chrome 中的弹出窗口
WebDriverWait wait = new WebDriverWait(driver, 18);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.sendKeys("username" + Keys.TAB + "password");
alert.accept();
当 Chrome 设置为无头时,不会显示窗口弹出窗口。我只能在屏幕截图中看到空白屏幕。
另外,我尝试将 chromeoptions 添加为
String path = "path to chromedriver";
System.setProperty("webdriver.chrome.driver", path);
System.setProperty("webdriver.chrome.logfile", "./chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--disable-popup-blocking");
driver = new ChromeDriver(options);
ChromeDriverLog 的默认值为
"default_content_settings": {
"geolocation": 1,
"mouselock": 1,
"notifications": 1,
"popups": 1,
"ppapi-broker": 1
}