Table of Contents

Class RemoteWebDriver

Namespace
OpenQA.Selenium.Remote
Assembly
WebDriver.dll

Provides a way to use the driver through

public class RemoteWebDriver : IWebDriver, IDisposable, ISearchContext, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, ITakesScreenshot, IHasInputDevices, IHasCapabilities, IAllowsFileDetection
Inheritance
RemoteWebDriver
Implements
Derived
Inherited Members

Examples

[TestFixture]
public class Testing
{
    private IWebDriver driver;

    [SetUp]
    public void SetUp()
    {
        driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),DesiredCapabilities.InternetExplorer());
    }

    [Test]
    public void TestGoogle()
    {
        driver.Navigate().GoToUrl("http://www.google.co.uk");
        /*
        *   Rest of the test
        */
    }

    [TearDown]
    public void TearDown()
    {
        driver.Quit();
    } 
}

Constructors

RemoteWebDriver(ICapabilities)

Initializes a new instance of the RemoteWebDriver class. This constructor defaults proxy to http://127.0.0.1:4444/wd/hub

public RemoteWebDriver(ICapabilities desiredCapabilities)

Parameters

desiredCapabilities ICapabilities

An ICapabilities object containing the desired capabilities of the browser.

RemoteWebDriver(ICommandExecutor, ICapabilities)

Initializes a new instance of the RemoteWebDriver class

public RemoteWebDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)

Parameters

commandExecutor ICommandExecutor

An ICommandExecutor object which executes commands for the driver.

desiredCapabilities ICapabilities

An ICapabilities object containing the desired capabilities of the browser.

RemoteWebDriver(Uri, ICapabilities)

Initializes a new instance of the RemoteWebDriver class

public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities)

Parameters

remoteAddress Uri

URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).

desiredCapabilities ICapabilities

An ICapabilities object containing the desired capabilities of the browser.

RemoteWebDriver(Uri, ICapabilities, TimeSpan)

Initializes a new instance of the RemoteWebDriver class using the specified remote address, desired capabilities, and command timeout.

public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)

Parameters

remoteAddress Uri

URI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).

desiredCapabilities ICapabilities

An ICapabilities object containing the desired capabilities of the browser.

commandTimeout TimeSpan

The maximum amount of time to wait for each command.

Fields

DefaultCommandTimeout

The default command timeout for HTTP requests in a RemoteWebDriver instance.

protected static readonly TimeSpan DefaultCommandTimeout

Field Value

TimeSpan

Properties

Capabilities

Gets the capabilities that the RemoteWebDriver instance is currently using

public ICapabilities Capabilities { get; }

Property Value

ICapabilities

CommandExecutor

Gets the ICommandExecutor which executes commands for this driver.

protected ICommandExecutor CommandExecutor { get; }

Property Value

ICommandExecutor

CurrentWindowHandle

Gets the current window handle, which is an opaque handle to this window that uniquely identifies it within this driver instance.

public string CurrentWindowHandle { get; }

Property Value

string

FileDetector

Gets or sets the IFileDetector responsible for detecting sequences of keystrokes representing file paths and names.

public virtual IFileDetector FileDetector { get; set; }

Property Value

IFileDetector

Keyboard

Gets an IKeyboard object for sending keystrokes to the browser.

public IKeyboard Keyboard { get; }

Property Value

IKeyboard

Mouse

Gets an IMouse object for sending mouse commands to the browser.

public IMouse Mouse { get; }

Property Value

IMouse

PageSource

Gets the source of the page last loaded by the browser.

public string PageSource { get; }

Property Value

string

SessionId

Gets the SessionId for the current session of this driver.

protected SessionId SessionId { get; }

Property Value

SessionId

Title

Gets the title of the current browser window.

public string Title { get; }

Property Value

string

Url

Gets or sets the URL the browser is currently displaying.

public string Url { get; set; }

Property Value

string
See Also
GoToUrl(Uri)

WindowHandles

Gets the window handles of open browser windows.

public ReadOnlyCollection<string> WindowHandles { get; }

Property Value

ReadOnlyCollection<string>

Methods

Close()

Closes the Browser

public void Close()

CreateElement(string)

Creates a RemoteWebElement with the specified ID.

protected virtual RemoteWebElement CreateElement(string elementId)

Parameters

elementId string

The ID of this element.

Returns

RemoteWebElement

A RemoteWebElement with the specified ID.

Dispose()

Dispose the RemoteWebDriver Instance

public void Dispose()

Dispose(bool)

Stops the client from running

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

if its in the process of disposing

Execute(string, Dictionary<string, object>)

Executes a command with this driver .

protected virtual Response Execute(string driverCommandToExecute, Dictionary<string, object> parameters)

Parameters

driverCommandToExecute string

A DriverCommand value representing the command to execute.

parameters Dictionary<string, object>

A Dictionary<TKey, TValue> containing the names and values of the parameters of the command.

Returns

Response

A Response containing information about the success or failure of the command and any data returned by the command.

ExecuteAsyncScript(string, params object[])

Executes JavaScript asynchronously in the context of the currently selected frame or window.

public object ExecuteAsyncScript(string script, params object[] args)

Parameters

script string

The JavaScript code to execute.

args object[]

The arguments to the script.

Returns

object

The value returned by the script.

ExecuteScript(string, params object[])

Executes JavaScript in the context of the currently selected frame or window

public object ExecuteScript(string script, params object[] args)

Parameters

script string

The JavaScript code to execute.

args object[]

The arguments to the script.

Returns

object

The value returned by the script.

ExecuteScriptCommand(string, string, params object[])

Executes JavaScript in the context of the currently selected frame or window using a specific command.

protected object ExecuteScriptCommand(string script, string commandName, params object[] args)

Parameters

script string

The JavaScript code to execute.

commandName string

The name of the command to execute.

args object[]

The arguments to the script.

Returns

object

The value returned by the script.

FindElement(By)

Finds the first element in the page that matches the By object

public IWebElement FindElement(By by)

Parameters

by By

By mechanism to find the object

Returns

IWebElement

IWebElement object so that you can interact with that object

Examples

IWebDriver driver = new InternetExplorerDriver();
IWebElement elem = driver.FindElement(By.Name("q"));

FindElement(string, string)

Finds an element matching the given mechanism and value.

protected IWebElement FindElement(string mechanism, string value)

Parameters

mechanism string

The mechanism by which to find the element.

value string

The value to use to search for the element.

Returns

IWebElement

The first IWebElement matching the given criteria.

FindElementByClassName(string)

Finds the first element in the page that matches the CSS Class supplied

public IWebElement FindElementByClassName(string className)

Parameters

className string

className of the

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementByClassName("classname")

FindElementByCssSelector(string)

Finds the first element matching the specified CSS selector.

public IWebElement FindElementByCssSelector(string cssSelector)

Parameters

cssSelector string

The CSS selector to match.

Returns

IWebElement

The first IWebElement matching the criteria.

FindElementById(string)

Finds the first element in the page that matches the ID supplied

public IWebElement FindElementById(string id)

Parameters

id string

ID of the element

Returns

IWebElement

IWebElement object so that you can interact with that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementById("id")

FindElementByLinkText(string)

Finds the first of elements that match the link text supplied

public IWebElement FindElementByLinkText(string linkText)

Parameters

linkText string

Link text of element

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByLinkText("linktext")

FindElementByName(string)

Finds the first of elements that match the name supplied

public IWebElement FindElementByName(string name)

Parameters

name string

Name of the element on the page

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
elem = driver.FindElementsByName("name")

FindElementByPartialLinkText(string)

Finds the first of elements that match the part of the link text supplied

public IWebElement FindElementByPartialLinkText(string partialLinkText)

Parameters

partialLinkText string

part of the link text

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByPartialLinkText("partOfLink")

FindElementByTagName(string)

Finds the first of elements that match the DOM Tag supplied

public IWebElement FindElementByTagName(string tagName)

Parameters

tagName string

DOM tag Name of the element being searched

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByTagName("tag")

FindElementByXPath(string)

Finds the first of elements that match the XPath supplied

public IWebElement FindElementByXPath(string xpath)

Parameters

xpath string

xpath to the element

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByXPath("//table/tbody/tr/td/a");

FindElements(By)

Finds the elements on the page by using the By object and returns a ReadOnlyCollection of the Elements on the page

public ReadOnlyCollection<IWebElement> FindElements(By by)

Parameters

by By

By mechanism to find the element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of IWebElement

Examples

IWebDriver driver = new InternetExplorerDriver();
ReadOnlyCollection<IWebElement> classList = driver.FindElements(By.ClassName("class"));

FindElements(string, string)

Finds all elements matching the given mechanism and value.

protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value)

Parameters

mechanism string

The mechanism by which to find the elements.

value string

The value to use to search for the elements.

Returns

ReadOnlyCollection<IWebElement>

A collection of all of the IWebElements matching the given criteria.

FindElementsByClassName(string)

Finds a list of elements that match the class name supplied

public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)

Parameters

className string

CSS class Name on the element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of IWebElement object so that you can interact with those objects

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByClassName("classname")

FindElementsByCssSelector(string)

Finds all elements matching the specified CSS selector.

public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector)

Parameters

cssSelector string

The CSS selector to match.

Returns

ReadOnlyCollection<IWebElement>

A ReadOnlyCollection<T> containing all IWebElements matching the criteria.

FindElementsById(string)

Finds the first element in the page that matches the ID supplied

public ReadOnlyCollection<IWebElement> FindElementsById(string id)

Parameters

id string

ID of the Element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of Elements that match the object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsById("id")

FindElementsByLinkText(string)

Finds a list of elements that match the link text supplied

public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)

Parameters

linkText string

Link text of element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection<IWebElement> object so that you can interact with those objects

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByClassName("classname")

FindElementsByName(string)

Finds a list of elements that match the name supplied

public ReadOnlyCollection<IWebElement> FindElementsByName(string name)

Parameters

name string

Name of element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollect of IWebElement objects so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByName("name")

FindElementsByPartialLinkText(string)

Finds a list of elements that match the class name supplied

public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText)

Parameters

partialLinkText string

part of the link text

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection<IWebElement> objects so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByPartialLinkText("partOfTheLink")

FindElementsByTagName(string)

Finds a list of elements that match the DOM Tag supplied

public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)

Parameters

tagName string

DOM tag Name of element being searched

Returns

ReadOnlyCollection<IWebElement>

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByTagName("tag")

FindElementsByXPath(string)

Finds a list of elements that match the XPath supplied

public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)

Parameters

xpath string

xpath to the element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of IWebElement objects so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByXpath("//tr/td/a")

GetScreenshot()

Gets a Screenshot object representing the image of the page on the screen.

public Screenshot GetScreenshot()

Returns

Screenshot

A Screenshot object containing the image.

Manage()

Method For getting an object to set the Speed

public IOptions Manage()

Returns

IOptions

Returns an IOptions object that allows the driver to set the speed and cookies and getting cookies

Examples

IWebDriver driver = new InternetExplorerDriver();
driver.Manage().GetCookies();
See Also

Navigate()

Method to allow you to Navigate with WebDriver

public INavigation Navigate()

Returns

INavigation

Returns an INavigation Object that allows the driver to navigate in the browser

Examples

IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.co.uk");

Quit()

Close the Browser and Dispose of WebDriver

public void Quit()

StartClient()

Starts the command executor, enabling communication with the browser.

protected virtual void StartClient()

StartSession(ICapabilities)

Starts a session with the driver

protected void StartSession(ICapabilities desiredCapabilities)

Parameters

desiredCapabilities ICapabilities

Capabilities of the browser

StopClient()

Stops the command executor, ending further communication with the browser.

protected virtual void StopClient()

SwitchTo()

Method to give you access to switch frames and windows

public ITargetLocator SwitchTo()

Returns

ITargetLocator

Returns an Object that allows you to Switch Frames and Windows

Examples

IWebDriver driver = new InternetExplorerDriver();
driver.SwitchTo().Frame("FrameName");