小编典典

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

selenium

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标签,该标签显示为“ Example
Domain”。该代码适用于http://www.example.com,但不适用于https://www.exmaple.com。我该如何解决这个问题?谢谢


阅读 326

收藏
2020-06-26

共1个答案

小编典典

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

2020-06-26