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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22247435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:32:20  来源:igfitidea点击:

Why won't PhantomJSDriver use the capabilities I set?

javaseleniumphantomjs

提问by Kerem356

I'm setting some capabilities for 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());

Output:

输出:

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}]

It shows:

表明:

cssSelectorsEnabled=true, 
applicationCacheEnabled=false,
acceptSslCerts=false

Why is the driver running without the capabilities I set?

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

回答by Nguyen Vu Hoang

PhantomJS uses different mechanism in setting capabilities

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

For more information about its command line, you could reference http://phantomjs.org/api/command-line.html

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

回答by Jules Clements

With phantomjsdriver-1.1I had to pass the follow arguments to get this to work.

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

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