【问题标题】:How to disable the authentication popup in chrome browser while running Selenium Script如何在运行 Selenium 脚本时禁用 chrome 浏览器中的身份验证弹出窗口
【发布时间】:2018-03-23 23:29:20
【问题描述】:

enter image description here通过第一个 URL,我点击登录(如图所示),这会导致我需要输入凭据的另一个 URL。但在该页面之前,我看到浏览器生成的弹出窗口无法被 Selenium 定位。 enter image description here。我的 chrome 浏览器版本是 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 设置中或通过脚本删除此弹出窗口吗?

提前致谢

【问题讨论】:

  • 您收到什么错误信息?你正在研究哪种语言? AutoIt 应该已经解决了您的问题。 WinWaitActive("Windows 安全") Send("admin") Send("{TAB}") Send("Password") Send("{ENTER}")
  • @ShoaibAkhtar :我没有收到任何错误。我在 JAVA 工作。我的所有脚本都在 Firefox 中传递(Chrome 支持的某些功能除外) 我的实际问题出现在我的第二个屏幕上 我在 chrome 浏览器中收到一个身份验证弹出窗口,我需要手动取消以继续脚本的其他部分
  • @DebanjanB :我也尝试了该配置。它没有达到目的

标签: java google-chrome selenium security selenium-webdriver


【解决方案1】:

以下代码为我工作

    Robot robot;
    try {
        robot = new Robot();
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } catch (AWTException e) {
        e.printStackTrace();
    }

【讨论】:

    猜你喜欢
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    相关资源
    最近更新 更多