OS: Windows 10 pro IDE: Eclipse Neon JDK: version 1.8.0_91 Selenium standalone server: version 3.0.1 phantom.exe: version 2.1.1 Windows phantom.jar: version 1.2.1 TestNG: version 6.9.9
说明: 我试图与硒的webdriver和Java一起使用phantomJS无头的浏览器。 我需要加载具有证书错误的https网址(本网站提供的安全证书不是由可信证书颁发机构颁发)。我需要通过这个问题。 我试图做到这一点(其他失败的尝试中)如下:无法使用硒的webdriver +幻影时加载的HTTPS URL
类initializeTest.java从那里被运行的TestNG的类的类
public class initializeTest{
public static WebDriver driver = null;
public static WebDriver settingBrowser(String browser) throws InterruptedException {
if(browser.equalsIgnoreCase("phantom")){
File file = new File("C:\\Program Files\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
DesiredCapabilities capabilitiesPhantomJS = DesiredCapabilities.phantomjs();
capabilitiesPhantomJS.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--ssl-protocol=tlsv1"});
capabilitiesPhantomJS.setPlatform(Platform.ANY);
capabilitiesPhantomJS.setJavascriptEnabled(true);
capabilitiesPhantomJS.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new PhantomJSDriver();
}
}
return driver;
}
代码摘录
@BeforeTest
public void navigate() throws InterruptedException{
String selectBrowser = "phantom"
this.driver = initializeTest.settingBrowser(selectBrowser);
driver.navigate().to(https://....);
thread.sleep(5000);
System.out.println(driver.getTitle());
System.out.println("Begin 2");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.urlContains("login"));
System.out.println(driver.getTitle());
}
结果:
1.第一个println运行并且没有任何内容被打印在控制台上。
2.打印“开始2”,并且最后一个println未执行(未找到url处的登录字符串)。
3.第三的println不执行
的原因是该URL没有加载,虽然我不明白为什么。 有没有人有想法或知道解决方法?
它的工作,谢谢,现在打开页面。 驱动程序=新PhantomJSDriver(capabilitiesPhantomJS); –
很酷。你能接受答案吗? –