You can specify PhantomJS' --web-security
command line options using PhantomJSDriverService.WebSecurity Property, rather than pass it as PhantomJSOptions
.
This is added in Selenium 2.32.0, a quote from CHANGELOG:
(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.
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
has other pre-defined command line arguments one can specify, please check documentation. Also
there are methods to add your own arguments.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…