Table of Contents

Class PhantomJSDriverService

Namespace
OpenQA.Selenium.PhantomJS
Assembly
WebDriver.dll

Exposes the service provided by the native PhantomJS executable and GhostDriver JavaScript library.

public sealed class PhantomJSDriverService : DriverService, ICommandServer, IDisposable
Inheritance
PhantomJSDriverService
Implements
Inherited Members

Properties

AdditionalArguments

Gets the list of arguments appended to the PhantomJS command line as a string array.

public ReadOnlyCollection<string> AdditionalArguments { get; }

Property Value

ReadOnlyCollection<string>

CommandLineArguments

Gets the command-line arguments for the driver service.

protected override string CommandLineArguments { get; }

Property Value

string

ConfigFile

Gets or sets the path to the JSON configuration file (in lieu of providing any other parameters).

public string ConfigFile { get; set; }

Property Value

string

Examples

var configOptions = PhantomJSDriverService.CreateDefaultService()
{
    CookiesFile = "cookiesFile",
    DiskCache = true,
    IgnoreSslErrors = true,
    LoadImages = true,
    LocalToRemoteUrlAccess = true,
    MaxDiskCacheSize = 1000,
    OutputEncoding = "abc",
    Proxy = "address:999",
    ProxyType = "socks5",
    ScriptEncoding = "def",
    SslProtocol = "sslv2",
    WebSecurity = true,
};

string json = configOptions.ToJson();

File.WriteAllText(@"C:\temp\myconfig.json", json);

var driverService = PhantomJSDriver.CreateDefaultService();
driverService.ConfigFile = @"C:\temp\myconfig.json";

var driver = new PhantomJSDriver(driverService);  // Launches PhantomJS.exe using JSON configuration file.

Remarks

If a PhantomJSDriverService instance is serialized to JSON, it can be saved to a file and used as a JSON configuration source for the PhantomJS.exe process.

CookiesFile

Gets or sets the file name used to store the persistent cookies.

public string CookiesFile { get; set; }

Property Value

string

DiskCache

Gets or sets a value indicating whether the disk cache is enabled (at desktop services cache storage location, default is no).

public bool DiskCache { get; set; }

Property Value

bool

GhostDriverPath

Gets or sets the location where the GhostDriver JavaScript file is located. This allows the use of an external implementation of GhostDriver instead of the implementation embedded inside the PhantomJS executable.

public string GhostDriverPath { get; set; }

Property Value

string

GridHubUrl

Gets or sets the URL of a Selenium Grid hub with which this PhantomJS instance should register.

public string GridHubUrl { get; set; }

Property Value

string

IPAddress

Gets or sets the IP address to use when starting the GhostDriver implementation embedded in PhantomJS.

public string IPAddress { get; set; }

Property Value

string

IgnoreSslErrors

Gets or sets a value indicating whether SSL errors are ignored, such as expired or self-signed certificate errors (default is no).

public bool IgnoreSslErrors { get; set; }

Property Value

bool

LoadImages

Gets or sets a value indicating whether all inlined images are loaded (default is yes).

public bool LoadImages { get; set; }

Property Value

bool

LocalStoragePath

Gets or sets the path to save LocalStorage content and WebSQL content.

public string LocalStoragePath { get; set; }

Property Value

string

LocalStorageQuota

Gets or sets the maximum size to allow for data.

public int LocalStorageQuota { get; set; }

Property Value

int

LocalToRemoteUrlAccess

Gets or sets a value indicating whether local content is allowed to access remote URL (default is no).

public bool LocalToRemoteUrlAccess { get; set; }

Property Value

bool

LogFile

Gets or sets the location of the log file to which PhantomJS will write log output. If this value is null or an empty string, the log output will be written to the console window.

public string LogFile { get; set; }

Property Value

string

MaxDiskCacheSize

Gets or sets the size limit of the disk cache in KB.

public int MaxDiskCacheSize { get; set; }

Property Value

int

OutputEncoding

Gets or sets the encoding used for terminal output (default is "utf8").

public string OutputEncoding { get; set; }

Property Value

string

Proxy

Gets or sets the proxy server information (in the format of {address} or {address}:{port}).

public string Proxy { get; set; }

Property Value

string

ProxyAuthentication

Gets or sets the proxy authentication info (e.g. username:password).

public string ProxyAuthentication { get; set; }

Property Value

string

ProxyType

Gets or sets the type of the proxy server ('http', 'socks5' or 'none').

public string ProxyType { get; set; }

Property Value

string

ScriptEncoding

Gets or sets the encoding used for the starting script (default is "utf8").

public string ScriptEncoding { get; set; }

Property Value

string

SslCertificatesPath

Gets or sets the location for custom CA certificates (if none set, uses system default).

public string SslCertificatesPath { get; set; }

Property Value

string

SslProtocol

Gets or sets the SSL protocol for secure connections ('sslv3' (default), 'sslv2', 'tlsv1' or 'any').

public string SslProtocol { get; set; }

Property Value

string

WebSecurity

Gets or sets a value indicating whether web security is enabled and forbids cross-domain XHR (default is yes).

public bool WebSecurity { get; set; }

Property Value

bool

Methods

AddArgument(string)

Adds a single argument to the list of arguments to be appended to the PhantomJS.exe command line.

public void AddArgument(string argument)

Parameters

argument string

The argument to add.

AddArguments(IEnumerable<string>)

Adds arguments to be appended to the PhantomJS.exe command line.

public void AddArguments(IEnumerable<string> arguments)

Parameters

arguments IEnumerable<string>

An IEnumerable<T> object of arguments to add.

AddArguments(params string[])

Adds arguments to be appended to the PhantomJS.exe command line.

public void AddArguments(params string[] arguments)

Parameters

arguments string[]

An array of arguments to add.

CreateDefaultService()

Creates a default instance of the PhantomJSDriverService.

public static PhantomJSDriverService CreateDefaultService()

Returns

PhantomJSDriverService

A PhantomJSDriverService that implements default settings.

CreateDefaultService(string)

Creates a default instance of the PhantomJSDriverService using a specified path to the PhantomJS executable.

public static PhantomJSDriverService CreateDefaultService(string driverPath)

Parameters

driverPath string

The directory containing the PhantomJS executable.

Returns

PhantomJSDriverService

A PhantomJSDriverService using a random port.

CreateDefaultService(string, string)

Creates a default instance of the PhantomJSDriverService using a specified path to the PhantomJS executable with the given name.

public static PhantomJSDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)

Parameters

driverPath string

The directory containing the PhantomJS executable.

driverExecutableFileName string

The name of the PhantomJS executable file.

Returns

PhantomJSDriverService

A PhantomJSDriverService using a random port.

ToJson()

Serializes the service options to JSON to be used as a configuration file for PhantomJS.exe (via the --config argument).

public string ToJson()

Returns

string

The JSON representation of the configured service options.