最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting service_args for phantomjs in selenium-webdriver for node - Stack Overflow

programmeradmin1浏览0评论

I need to be able to run phantomjs with the following arg:

--ignore-ssl-errors=true

The page I'm testing uses a self-signed cert so I need the arg to open the page. I'm trying to pass the arg in webdriver using the snippet below:

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

Is the correct way to pass the service_args? I actually hope not since I can't load my test page. I can open the page by running:

phantomjs --ignore-ssl-errors=true myTest.js

Here is the code in myTest.js

var page = new WebPage();
page.open('/', function (status) {
        just_wait();
});

function just_wait() {
    setTimeout(function() {
            page.render('screenshot.png');
            phantom.exit();
    }, 2000);
}

I need to be able to run phantomjs with the following arg:

--ignore-ssl-errors=true

The page I'm testing uses a self-signed cert so I need the arg to open the page. I'm trying to pass the arg in webdriver using the snippet below:

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

Is the correct way to pass the service_args? I actually hope not since I can't load my test page. I can open the page by running:

phantomjs --ignore-ssl-errors=true myTest.js

Here is the code in myTest.js

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

function just_wait() {
    setTimeout(function() {
            page.render('screenshot.png');
            phantom.exit();
    }, 2000);
}
Share Improve this question asked Jul 2, 2014 at 4:29 user3047479user3047479 1672 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

The correct answer is:

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

documented here: https://github./detro/ghostdriver/issues/233

In case someone will need it for facebook/php-webdriver CLI arguments can be passed to PhantomJS in a following manner:

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

Reading this I got really confused, as the accepted answer is in Java, and the GhostDriver constants and stuff aren't present. For those who are also confused, this worked for me:

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();
发布评论

评论列表(0)

  1. 暂无评论