本文介绍了为什么PhantomJSDriver不会使用我设置的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为设置一些功能PhantomJsDriver
。
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("cssSelectorsEnabled", false);
caps.setCapability("applicationCacheEnabled", true);
caps.setCapability("acceptSslCerts",true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,phantomJsPath);
this.driver = new PhantomJSDriver(caps);
然后,我检查驱动程序使用的功能:
Then, I check what capabilities the driver is using:
System.out.println(driver.getCapabilities());
输出:
Capabilities [{
platform=XP,
acceptSslCerts=false,
javascriptEnabled=true,
browserName=phantomjs,
rotatable=false,
driverVersion=1.1.0,
locationContextEnabled=false,
version=1.9.7,
cssSelectorsEnabled=true,
databaseEnabled=false,
handlesAlerts=false,
browserConnectionEnabled=false,
proxy={proxyType=direct},
nativeEvents=true,
webStorageEnabled=false,
driverName=ghostdriver,
applicationCacheEnabled=false,
takesScreenshot=true}]
显示:
cssSelectorsEnabled=true,
applicationCacheEnabled=false,
acceptSslCerts=false
为什么驱动程序在没有我设置的功能的情况下运行?
Why is the driver running without the capabilities I set?
推荐答案
PhantomJS在设置功能时使用不同的机制
PhantomJS uses different mechanism in setting capabilities
static ArrayList<String> cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability("takesScreenshot", true);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,
new String[] { "--logLevel=2" });
this.driver = new PhantomJSDriver(capabilities);
有关其命令行的更多信息,可以参考
For more information about its command line, you could reference http://phantomjs.org/api/command-line.html
这篇关于为什么PhantomJSDriver不会使用我设置的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!