指定PhantomJS命令行optionsto硒PhantomJSDriver [英] Specify PhantomJS command line optionsto Selenium PhantomJSDriver

查看:548
本文介绍了指定PhantomJS命令行optionsto硒PhantomJSDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否PhantomJS驱动程序支持命令行参数?我需要运行与PhantomJS司机和禁用Web安全Selenium测试。我曾尝试:

Does the PhantomJS driver support command line arguments? I need to run Selenium tests with the PhantomJS driver and disable web security. I have tried:

PhantomJSOptions options = new PhantomJSOptions();           
options.AddAdditionalCapability("web-security",false);             
driver = new PhantomJSDriver(Environment.CurrentDirectory + @"\drivers", options);



但这似乎并没有工作。 ?是否PhantomJSDriver允许通过命令行参数

but this does not seem to work. Does the PhantomJSDriver allow for passing command line arguments?

推荐答案

您可以指定PhantomJS - 基于Web使用的命令行选项=nofollow的> PhantomJSDriverService.WebSecurity物业,而不是把它作为 PhantomJSOptions

You can specify PhantomJS' --web-security command line options using PhantomJSDriverService.WebSecurity Property, rather than pass it as PhantomJSOptions.

这硒2.32.0加入,从更新日志报价:

This is added in Selenium 2.32.0, a quote from CHANGELOG:

(代表GeoffMcElhanon)的新增支持参数传递给
PhantomJS。该PhantomJSDriverService现在拥有了所有的命令行开关由PhantomJS支持的类型安全属性
。这些
可以直接在命令行上传递,或可序列化
成JSON文件与--config命令行开关
传递给PhantomJS。

(on behalf of GeoffMcElhanon) Added support to pass arguments to PhantomJS. The PhantomJSDriverService now has type-safe properties for all of the command-line switches supported by PhantomJS. These can be passed directly on the command line, or can be serialized into a JSON file for passing with the --config command line switch to PhantomJS.

下面是未经测试的代码,请参考相关文档(该WebDriver.chm在硒的zip文件),在必要的时候。

Below is the untested code, please refer to the documentation (the WebDriver.chm in your Selenium zip file) when necessary.

var service = PhantomJSDriverService.CreateDefaultService(Environment.CurrentDirectory + @"\drivers");
service.WebSecurity = false;
var driver = new PhantomJSDriver(service);



PhantomJSDriverService 还有其他预先定义的命令行一个参数可以指定,请查阅文档。此外
有方法来添加自己的论点

PhantomJSDriverService has other pre-defined command line arguments one can specify, please check documentation. Also there are methods to add your own arguments.

AddArgument():将单个参数参数列表将追加到PhantomJS.exe命令行结果
AddArguments(IEnumerable的):添加参数追加到PhantomJS.exe命令行<。 BR>
AddArguments(字符串[]):添加参数追加到PhantomJS.exe命令行。

AddArgument(): Adds a single argument to the list of arguments to be appended to the PhantomJS.exe command line.
AddArguments(IEnumerable): Adds arguments to be appended to the PhantomJS.exe command line.
AddArguments(String[]): Adds arguments to be appended to the PhantomJS.exe command line.

这篇关于指定PhantomJS命令行optionsto硒PhantomJSDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆