使用Selenium在Chrome上处理“您对此站点的连接不是私有的”弹出窗口

时间:2019-04-05 06:26:54

标签: java selenium google-chrome

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

1-浏览URL 1

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

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

enter image description here

我整天都在玩,但是没有运气可以绕过这个弹出窗口。尝试过:

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();
}

}

2 个答案:

答案 0 :(得分:1)

创建DesiredCapabilities类的实例:-

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

答案 1 :(得分:0)

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

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

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

http://sikulix.com/

相关问题