Specify PhantomJS command line optionsto Selenium PhantomJSDriver(为 Selenium PhantomJSDriver 指定 PhantomJS 命令行选项)
问题描述
PhantomJS 驱动程序是否支持命令行参数?我需要使用 PhantomJS 驱动程序运行 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?
推荐答案
您可以使用 --web-security 命令行选项.com/p/selenium/source/browse/dotnet/src/WebDriver/PhantomJS/PhantomJSDriverService.cs#178" rel="nofollow">PhantomJSDriverService.WebSecurity 属性,而不是将其作为 PhantomJSOptions代码>.
You can specify PhantomJS' --web-security
command line options using PhantomJSDriverService.WebSecurity Property, rather than pass it as PhantomJSOptions
.
这是在 Selenium 2.32.0 中添加的,引用自 CHANGELOG:
This is added in Selenium 2.32.0, a quote from CHANGELOG:
(代表 GeoffMcElhanon)添加了对传递参数的支持幻影JS.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.
以下是未经测试的代码,必要时请参考文档(Selenium zip 文件中的 WebDriver.chm).
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 命令行的参数.
AddArguments(String[]): 添加要附加到 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.
这篇关于为 Selenium PhantomJSDriver 指定 PhantomJS 命令行选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为 Selenium PhantomJSDriver 指定 PhantomJS 命令行选项
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01