为什么PhantomJSDriver不会使用我设置的function?

我正在为PhantomJsDriver设置一些function。

 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); 

然后,我检查驱动程序使用的function:

 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 

为什么驱动程序没有我设置的function运行?

PhantomJS在设置function时使用不同的机制

 static ArrayList cliArgsCap = new ArrayList(); 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); 

有关其命令行的更多信息,请参阅http://phantomjs.org/api/command-line.html

使用phantomjsdriver-1.1我必须传递以下参数才能使其工作。

 cliArgsCap.add("--web-security=no"); cliArgsCap.add("--ignore-ssl-errors=yes");