use*_*296 3 selenium phantomjs
我正在尝试使用无头webkit of PhantomJs通过selenium webdriver打开google.com,但是当我执行代码系统时会抛出错误.phantomJs.exe放在E目录中.请帮我解决这个问题.
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "E:\\phantomjs.exe");
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
}
Run Code Online (Sandbox Code Playgroud)
错误:
线程"main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由phantomjs.binary.path功能/系统属性/ PATH变量设置; 有关更多信息,请参阅https://github.com/ariya/phantomjs/wiki.最新版本可以从http://phantomjs.org/download.html下载 在org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService的org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:236)的com.google.common.base.Preconditions.checkState(Preconditions.java:197)上(PhantomJSDriverService.java:181)org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104)at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94)at multidrivers.main(multidrivers.的java:35)
线程"main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由phantomjs.binary.path功能/系统属性/ PATH变量设置;
上述问题是由于未使用DesiredCapabilities对象初始化驱动程序:
WebDriver driver = new PhantomJSDriver();
Run Code Online (Sandbox Code Playgroud)
如下更新代码可以解决您的问题:
WebDriver driver = new PhantomJSDriver(caps);
Run Code Online (Sandbox Code Playgroud)
如果您有任何疑问,请告诉我.
| 归档时间: |
|
| 查看次数: |
12254 次 |
| 最近记录: |