PhantomJSDriver适用于HTTP,但不适用于HTTPS

时间:2014-06-24 23:25:55

标签: java selenium phantomjs

public class FooTest {
    WebDriver driver;

    @Before
    public void beforeTest() {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setJavascriptEnabled(true);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

        driver = new PhantomJSDriver(capabilities);
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
    }

    @Test
    public void test() {
        driver.get("http://www.example.com");

        WebElement e = driver.findElement(By.tagName("h1"));
        System.out.println("TEXT" + e.getAttribute("innerHTML"));
        assertNotNull(e);
        driver.quit();
    }

}

嗨,我只是想在www.example.com上尝试获取h1标签,其中包含"示例域名。"该代码适用于http://www.example.com,但不适用于https://www.exmaple.com。我该如何解决这个问题?感谢

1 个答案:

答案 0 :(得分:5)

PhantomJSDriver不支持(全部)DesiredCapabilities。

您将需要:

caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
driver = new PhantomJSDriver(caps);

此处记录:https://github.com/detro/ghostdriver/issues/233