【问题标题】:Setting service_args for phantomjs in selenium-webdriver for node在节点的 selenium-webdriver 中为 phantomjs 设置 service_args
【发布时间】:2016-06-27 19:54:57
【问题描述】:

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

--ignore-ssl-errors=true

我正在测试的页面使用自签名证书,因此我需要 arg 来打开页面。我正在尝试使用下面的 sn-p 在 webdriver 中传递 arg:

capabilities = webdriver.Capabilities.phantomjs();
capabilities.set('service_args', '--ignore-ssl-errors=true');
driver = new webdriver.Builder().
    withCapabilities(capabilities).
    build();

传递 service_args 的正确方法是什么?我实际上希望不会,因为我无法加载我的测试页面。我可以通过运行打开页面:

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

【问题讨论】:

    标签: javascript selenium-webdriver phantomjs


    【解决方案1】:

    正确答案是:

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

    在此处记录:https://github.com/detro/ghostdriver/issues/233

    【讨论】:

      【解决方案2】:

      如果有人需要 facebook/php-webdriver 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']
      ]);
      

      【讨论】:

        【解决方案3】:

        读到这里我真的很困惑,因为公认的答案是在 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();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-08-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多