Selenium webdriver 使用Selenium webDriver检查网站是否存在任何ssl证书警告

Selenium webdriver 使用Selenium webDriver检查网站是否存在任何ssl证书警告,selenium-webdriver,Selenium Webdriver,我需要自动化一个场景,在这个场景中,我必须验证网站是否没有关于ssl证书的警告。如何使用Selenium WebDriver 2对其进行存档?SSL证书警告在每个浏览器上显示不同(因为它们是由浏览器本身生成的,而不是由您尝试访问的网页生成的) 如果您在Firefox中使用Selenium,则可以使用以下Java类: import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; imp

我需要自动化一个场景,在这个场景中,我必须验证网站是否没有关于ssl证书的警告。如何使用Selenium WebDriver 2对其进行存档?

SSL证书警告在每个浏览器上显示不同(因为它们是由浏览器本身生成的,而不是由您尝试访问的网页生成的)

如果您在Firefox中使用Selenium,则可以使用以下Java类:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxBinary;

class Whatever
{
    private WebDriver webDriver;

    public void open() throws Exception
    {
        webDriver = new FirefoxDriver();
    }

    public void openHeadless() throws Exception
    {
        FirefoxBinary binary = new FirefoxBinary(new File("/usr/local/bin/firefox"));
        binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":99"));
        webDriver = new FirefoxDriver(binary,null);
    }

    public void close() throws Exception
    {
        webDriver.quit();
    }

    public boolean sslWarningIssued(final String url) throws Exception
    {
        webDriver.get(url);
        String pageSource = webDriver.getPageSource();
        return webDriver.getTitle().equals("Untrusted Connection"); // should be faster than the one below...
        return pageSource.contains("This Connection is Untrusted") && pageSource.contains("What Should I Do?");
    }
}
然后你可以打电话:

Whatever instance = new Whatever();
instance.open(); // or openHeadless for faster execution
boolean sslWarningIssued1 = instance.sslWarningIssued(website_1_url);
boolean sslWarningIssued2 = instance.sslWarningIssued(website_2_url);
...
boolean sslWarningIssuedN = instance.sslWarningIssued(website_N_url);
instance.close();

能否提供一个导致浏览器显示SSL证书警告的URL?URL:请参阅此198.50.236.249:2083