[英]Set user-agent with selenium-webdriver and phantomjs in nodejs
[英]Setting service_args for phantomjs in selenium-webdriver for node
我需要能够使用以下arg运行phantomjs:
- 忽略SSL的错误=真
我正在测试的页面使用自签名证书,因此我需要arg打开页面。 我正在尝试使用以下代码片段在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);
}
正确答案是:
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);
万一有人需要它用于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']
]);
读完这篇文章后,我感到非常困惑,因为可接受的答案是在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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.