java - 如何在运行 Selenium 脚本时禁用 chrome 浏览器中的身份验证弹出窗口

标签 java google-chrome selenium security selenium-webdriver

enter image description here通过第一个 URL,我单击登录(如图所示),这导致我需要输入凭据的另一个 URL。但在该页面之前,我看到浏览器生成的弹出窗口无法被 Selenium 定位。 enter image description here .我的 chrome 浏览器版本是 Version 61.0.3163.100 (Official Build) (64-bit)

我尝试使用以下方法:

  1. Alert.dismiss()

  2. JavaScript

    ((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return
    

    是的; }");

  3. AutoIt

    WinWaitActive("Windows Security")
    Send("admin{TAB}")
    Send("Password{Enter}")
    
  4. 机器人类

    alert.sendKeys("UserName");
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    alert.sendKeys("Password");
    alert.accept();
    
  5. 还尝试通过在 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/

相关文章:

java - com.google.gson.JsonSyntaxException 试图解析 json 中的日期/时间

java - Mockito 监视被单元测试的对象

java - 如何在 Vaadin 8 中绑定(bind)外键

html - 如何设置月份类型输入的默认内容?

java - 从java触发chrome中的事件

java - Flyway ClassNotFoundException : JavaUtilLogCreator

python - 如何添加或删除 Chrome 扩展 "after"selenium 网络驱动程序已实例化/定义

python - 如何使用 Python + Selenium 从警告框中读取文本

python - Selenium 和 BeautifulSoup : sharing and pulling session data resources to multiple libraries in python

javascript - 类切换 CSS 动画在 Chrome 中无法正确切换帧