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

Ker*_*356 9 java selenium phantomjs

我正在设置一些功能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);
Run Code Online (Sandbox Code Playgroud)

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

System.out.println(driver.getCapabilities());
Run Code Online (Sandbox Code Playgroud)

输出:

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}]
Run Code Online (Sandbox Code Playgroud)

表明:

cssSelectorsEnabled=true, 
applicationCacheEnabled=false,
acceptSslCerts=false
Run Code Online (Sandbox Code Playgroud)

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

Ngu*_*ang 18

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

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);
Run Code Online (Sandbox Code Playgroud)

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