本文介绍了PhantomJSDriver适用于HTTP,但不适用于HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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标签,其中显示示例域。该代码适用于,但不适用于。我该如何解决这个问题?谢谢
Hi, I'm just simply trying get the h1 tag in www.example.com which says "Example Domain." The code works for http://www.example.com but not for https://www.exmaple.com. How can I fix this problem? Thanks
推荐答案
PhantomJSDriver不支持(全部)DesiredCapabilities。
PhantomJSDriver does not support (all) 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);
此处记录:
这篇关于PhantomJSDriver适用于HTTP,但不适用于HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!