【问题标题】:Handling "Your connection to this site is not private" popup on Chrome using Selenium使用 Selenium 在 Chrome 上处理“您与此站点的连接不是私有的”弹出窗口
【发布时间】:2019-04-05 06:26:54
【问题描述】:

我在进行自动化开发时遇到了问题。

1 - 浏览网址 1

2 - 它会自动重定向到 URL 2

3 - 具有 HTTP/基本身份验证

我玩了一整天,但没有运气绕过这个弹出窗口。试过了:

i - Chrome 参数

ii - 嵌入用户名/密码到 1URL

iii - 机器人

iv - 切换到 alert() setAuthentication/sendkeys

感谢您的建议

PS:考虑使用 AutoIt 或 Sikuli 来处理它。但是,我很想知道如何在不使用第三方的情况下处理它。

使用的代码片段

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Test {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    long startTime = System.currentTimeMillis();

    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type");
    options.addArguments("ignore-certificate-errors");
    options.setAcceptInsecureCerts(true);

    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().maximize();

    driver.get("http://username:password@URL1");

    // Being redirected to URL2
    // Stucked forever at HTTP/ Basic Authentication

    driver.findElement(By.id("username")).sendKeys("username");
    driver.findElement(By.id("password")).sendKeys("password");
    driver.findElement(By.id("kc-login")).click();
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       

    driver.close();
}

}

【问题讨论】:

  • @DebanjanB 添加了更多信息。在到达这里之前,我尝试了将用户名/密码放到 URL 上的解决方案,但它不起作用。
  • 问题中的步骤 3A 直接指向 HTTP / Basic Authentication。我错过了什么吗?您能否用不起作用以及代码试验错误堆栈跟踪的确切含义来更新问题?
  • 添加了使用的代码片段并再次更新 Q。它一直停留在 HTTP/Basic Auth 弹出窗口,没有给出任何错误/异常。

标签: java selenium google-chrome


【解决方案1】:

创建 DesiredCapabilities 类的实例:-

DesiredCapabilities handErr = DesiredCapabilities.chrome ()
handErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true) WebDriver driver = new ChromeDriver (handErr);

【讨论】:

    【解决方案2】:

    Chrome 似乎不再支持与对话框交互的功能。 JS、Java 或 Python 都无法在操作系统级别轻松地为此进行交互。

    driver.get("http://username:password@URL1");
    

    但您可以使用 Sikuli 进行 OCR 图像识别并处理弹出窗口。 它有 Java 支持和一个 IDE

    http://sikulix.com/

    【讨论】:

      猜你喜欢
      • 2021-02-17
      • 1970-01-01
      • 2017-04-28
      • 2013-02-03
      • 1970-01-01
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多