enter image description here通过第一个 URL,我单击登录(如图所示),这导致我需要输入凭据的另一个 URL。但在该页面之前,我看到浏览器生成的弹出窗口无法被 Selenium 定位。 enter image description here .我的 chrome 浏览器版本是 Version 61.0.3163.100 (Official Build) (64-bit)
我尝试使用以下方法:
Alert.dismiss()
JavaScript
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return
是的; }");
AutoIt
WinWaitActive("Windows Security") Send("admin{TAB}") Send("Password{Enter}")
机器人类
alert.sendKeys("UserName"); Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); alert.sendKeys("Password"); alert.accept();
还尝试通过在 URL 中输入用户名和密码来浏览第二个 URL
除此之外还在我的 selenium 脚本中使用了一些 Chrome 选项
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
options.addArguments("chrome.switches","--disable-extensions");
driver = new ChromeDriver(options);
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
有没有其他方法可以在 chrome 设置中或通过脚本删除此弹出窗口?
提前致谢
最佳答案
以下代码为我工作
Robot robot;
try {
robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
关于java - 如何在运行 Selenium 脚本时禁用 chrome 浏览器中的身份验证弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46702618/