Class RemoteWebDriver
Provides a way to use the driver through
public class RemoteWebDriver : IWebDriver, ISearchContext, IDisposable, IJavaScriptExecutor, IFindsById, IFindsByClassName, IFindsByLinkText, IFindsByName, IFindsByTagName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, ITakesScreenshot, IHasInputDevices, IHasCapabilities, IHasWebStorage, IHasLocationContext, IHasApplicationCache, IAllowsFileDetection, IHasSessionId, IActionExecutor
- 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(DriverOptions)
Initializes a new instance of the RemoteWebDriver class. This constructor defaults proxy to http://127.0.0.1:4444/wd/hub
public RemoteWebDriver(DriverOptions options)
Parameters
options
DriverOptionsAn DriverOptions object containing the desired capabilities of the browser.
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
ICapabilitiesAn 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
ICommandExecutorAn ICommandExecutor object which executes commands for the driver.
desiredCapabilities
ICapabilitiesAn ICapabilities object containing the desired capabilities of the browser.
RemoteWebDriver(Uri, DriverOptions)
Initializes a new instance of the RemoteWebDriver class. This constructor defaults proxy to http://127.0.0.1:4444/wd/hub
public RemoteWebDriver(Uri remoteAddress, DriverOptions options)
Parameters
remoteAddress
UriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
options
DriverOptionsAn DriverOptions 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
UriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
desiredCapabilities
ICapabilitiesAn 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
UriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
desiredCapabilities
ICapabilitiesAn ICapabilities object containing the desired capabilities of the browser.
commandTimeout
TimeSpanThe 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
Properties
ApplicationCache
Gets an IApplicationCache object for managing application cache.
public IApplicationCache ApplicationCache { get; }
Property Value
Capabilities
Gets the capabilities that the RemoteWebDriver instance is currently using
public ICapabilities Capabilities { get; }
Property Value
CommandExecutor
Gets the ICommandExecutor which executes commands for this driver.
protected ICommandExecutor CommandExecutor { get; }
Property Value
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
ElementFactory
Gets or sets the factory object used to create instances of RemoteWebElement or its subclasses.
protected RemoteWebElementFactory ElementFactory { get; set; }
Property Value
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
HasApplicationCache
Gets a value indicating whether manipulating the application cache is supported for this driver.
public bool HasApplicationCache { get; }
Property Value
HasLocationContext
Gets a value indicating whether manipulating geolocation is supported for this driver.
public bool HasLocationContext { get; }
Property Value
HasWebStorage
Gets a value indicating whether web storage is supported for this driver.
public bool HasWebStorage { get; }
Property Value
IsActionExecutor
Gets a value indicating whether this object is a valid action executor.
public bool IsActionExecutor { get; }
Property Value
Keyboard
Gets an IKeyboard object for sending keystrokes to the browser.
public IKeyboard Keyboard { get; }
Property Value
LocationContext
Gets an ILocationContext object for managing browser location.
public ILocationContext LocationContext { get; }
Property Value
Mouse
Gets an IMouse object for sending mouse commands to the browser.
public IMouse Mouse { get; }
Property Value
PageSource
Gets the source of the page last loaded by the browser.
public string PageSource { get; }
Property Value
SessionId
Gets the SessionId for the current session of this driver.
public SessionId SessionId { get; }
Property Value
Title
Gets the title of the current browser window.
public string Title { get; }
Property Value
Url
Gets or sets the URL the browser is currently displaying.
public string Url { get; set; }
Property Value
- See Also
-
GoToUrl(Uri)
WebStorage
Gets an IWebStorage object for managing web storage.
public IWebStorage WebStorage { get; }
Property Value
WindowHandles
Gets the window handles of open browser windows.
public ReadOnlyCollection<string> WindowHandles { get; }
Property Value
Methods
Close()
Closes the Browser
public void Close()
CreateElement(string)
Creates a RemoteWebElement with the specified ID.
[Obsolete("This method is no longer called to create RemoteWebElement instances. Implement a subclass of RemoteWebElementFactory and set the ElementFactory property to create instances of custom RemoteWebElement subclasses.")]
protected virtual RemoteWebElement CreateElement(string elementId)
Parameters
elementId
stringThe ID of this element.
Returns
- RemoteWebElement
A RemoteWebElement with the specified ID.
CreateElement(string, Dictionary<string, object>)
Creates a RemoteWebElement with the specified ID and element attributes.
protected virtual RemoteWebElement CreateElement(string id, Dictionary<string, object> elementDictionary)
Parameters
id
stringelementDictionary
Dictionary<string, object>The attributes for 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
boolif 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
stringA 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
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
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
stringThe JavaScript code to execute.
commandName
stringThe 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
ByBy 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
stringThe mechanism by which to find the element.
value
stringThe 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
stringclassName 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
stringThe 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
stringID 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
stringLink 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
stringName 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
stringpart 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
stringDOM 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
stringxpath 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
ByBy 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
stringThe mechanism by which to find the elements.
value
stringThe 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
stringCSS 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
stringThe 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
stringID 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
stringLink 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
stringName 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
stringpart 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
stringDOM 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
stringxpath 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")
GetCapabilitiesDictionary(ICapabilities)
Gets the capabilities as a dictionary.
protected virtual Dictionary<string, object> GetCapabilitiesDictionary(ICapabilities capabilitiesToConvert)
Parameters
capabilitiesToConvert
ICapabilitiesThe dictionary to return.
Returns
- Dictionary<string, object>
A Dictionary consisting of the capabilities requested.
Remarks
This method is only transitional. Do not rely on it. It will be removed once browser driver capability formats stabilize.
GetLegacyCapabilitiesDictionary(ICapabilities)
Gets the capabilities as a dictionary supporting legacy drivers.
protected virtual Dictionary<string, object> GetLegacyCapabilitiesDictionary(ICapabilities legacyCapabilities)
Parameters
legacyCapabilities
ICapabilitiesThe dictionary to return.
Returns
- Dictionary<string, object>
A Dictionary consisting of the capabilities requested.
Remarks
This method is only transitional. Do not rely on it. It will be removed once browser driver capability formats stabilize.
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");
PerformActions(IList<ActionSequence>)
Performs the specified list of actions with this action executor.
public void PerformActions(IList<ActionSequence> actionSequenceList)
Parameters
actionSequenceList
IList<ActionSequence>The list of action sequences to perform.
Quit()
Close the Browser and Dispose of WebDriver
public void Quit()
ResetInputState()
Resets the input state of the action executor.
public void ResetInputState()
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
ICapabilitiesCapabilities 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");