How to add PhantomJSDriver command line arguments

2019-07-08 04:56发布

问题:

This question already has an answer here:

  • Why won't PhantomJSDriver use the capabilities I set? 2 answers

How can I specify command line arguments for my Java PhantomJSDriver? For example, I want to set --ignore-ssl-errors=yes on the script that I run.

回答1:

Simply add to phantomJS's default desired capabilities, like so:

DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs();
desiredCapabilities.setCapability("phantomjs.cli.args", Collections.singletonList("--ignore-ssl-errors=yes"));

PhantomJSDriver driver = new PhantomJSDriver(desiredCapabilities);