Javascript 在SeleniumWebDriver中为节点的phantomjs设置服务参数

Javascript 在SeleniumWebDriver中为节点的phantomjs设置服务参数,javascript,selenium-webdriver,phantomjs,Javascript,Selenium Webdriver,Phantomjs,我需要能够使用以下参数运行phantomjs: --忽略ssl错误=true 我正在测试的页面使用自签名证书,因此我需要arg来打开页面。我正在尝试使用以下代码段在webdriver中传递参数: capabilities = webdriver.Capabilities.phantomjs(); capabilities.set('service_args', '--ignore-ssl-errors=true'); driver = new webdriver.Builder(). w

我需要能够使用以下参数运行phantomjs:

--忽略ssl错误=true

我正在测试的页面使用自签名证书,因此我需要arg来打开页面。我正在尝试使用以下代码段在webdriver中传递参数:

capabilities = webdriver.Capabilities.phantomjs();
capabilities.set('service_args', '--ignore-ssl-errors=true');
driver = new webdriver.Builder().
    withCapabilities(capabilities).
    build();
通过服务参数的正确方法是什么?我真的希望不会,因为我无法加载我的测试页面。我可以通过运行以下命令打开页面:

phantomjs --ignore-ssl-errors=true myTest.js
下面是myTest.js中的代码

var page = new WebPage();
page.open('https://my.somefaketestpage.com/', function (status) {
        just_wait();
});

function just_wait() {
    setTimeout(function() {
            page.render('screenshot.png');
            phantom.exit();
    }, 2000);
}
正确答案是:

caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
driver = new PhantomJSDriver(caps);

此处记录:

如果有人需要它作为CLI参数,可以通过以下方式将其传递给PhantomJS:

$driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', [
    WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::PHANTOMJS,
    WebDriverCapabilityType::PLATFORM     => WebDriverPlatform::ANY,
    'phantomjs.cli.args'                  => ['--ignore-ssl-errors=true']
]);

读到这篇文章我真的很困惑,因为公认的答案是Java,而GhostDriver常量和其他东西都不存在。对于那些同样感到困惑的人来说,这对我很有用:

var webdriver = require('selenium-webdriver'),
    Capabilities = webdriver.Capabilities;

var capability = Capabilities
        .phantomjs()
        .set('phantomjs.cli.args', '--ignore-ssl-errors=true');

var driver = new webdriver
        .Builder()
        .withCapabilities(capability)
        .build();