Class RemoteWebDriver
Provides a way to use the driver through
public class RemoteWebDriver : WebDriver, IWebDriver, IDisposable, ISearchContext, IJavaScriptExecutor, IFindsElement, ITakesScreenshot, ISupportsPrint, IActionExecutor, IAllowsFileDetection, IHasCapabilities, IHasCommandExecutor, IHasSessionId, ICustomDriverCommandExecutor, IHasVirtualAuthenticator, IDevTools, IHasDownloads
- Inheritance
-
RemoteWebDriver
- Implements
- Inherited Members
- Extension Methods
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"),new FirefoxOptions());
}
[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 capabilities)
Parameters
capabilities
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 capabilities)
Parameters
commandExecutor
ICommandExecutorAn ICommandExecutor object which executes commands for the driver.
capabilities
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 capabilities)
Parameters
remoteAddress
UriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
capabilities
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 capabilities, TimeSpan commandTimeout)
Parameters
remoteAddress
UriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
capabilities
ICapabilitiesAn ICapabilities object containing the desired capabilities of the browser.
commandTimeout
TimeSpanThe maximum amount of time to wait for each command.
Fields
RemoteDevToolsEndPointCapabilityName
The name of the Selenium grid remote DevTools end point capability.
public readonly string RemoteDevToolsEndPointCapabilityName
Field Value
RemoteDevToolsVersionCapabilityName
The name of the Selenium remote DevTools version capability.
public readonly string RemoteDevToolsVersionCapabilityName
Field Value
Properties
HasActiveDevToolsSession
Gets a value indicating whether a DevTools session is active.
public bool HasActiveDevToolsSession { get; }
Property Value
Methods
CloseDevToolsSession()
Closes a DevTools session.
public void CloseDevToolsSession()
DeleteDownloadableFiles()
Deletes all downloadable files.
public void DeleteDownloadableFiles()
Dispose(bool)
Releases all resources associated with this RemoteWebDriver.
protected override void Dispose(bool disposing)
Parameters
DownloadFile(string, string)
Downloads a file with the specified file name.
public void DownloadFile(string fileName, string targetDirectory)
Parameters
fileName
stringThe name of the file to be downloaded.
targetDirectory
stringThe target directory where the file should be downloaded to.
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
IWebElement elem = driver.FindElementsByXPath("//table/tbody/tr/td/a");
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
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(new FirefoxOptions());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByXpath("//tr/td/a")
GetDevToolsSession()
Creates a session to communicate with a browser using a Developer Tools debugging protocol.
public DevToolsSession GetDevToolsSession()
Returns
- DevToolsSession
The active session to use to communicate with the Developer Tools debugging protocol.
GetDevToolsSession(DevToolsOptions)
Creates a session to communicate with a browser using a Developer Tools debugging protocol.
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
Parameters
options
DevToolsOptions
Returns
- DevToolsSession
The active session to use to communicate with the Developer Tools debugging protocol.
GetDevToolsSession(int)
Creates a session to communicate with a browser using a specific version of the Developer Tools debugging protocol.
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
public DevToolsSession GetDevToolsSession(int protocolVersion)
Parameters
protocolVersion
intThe specific version of the Developer Tools debugging protocol to use.
Returns
- DevToolsSession
The active session to use to communicate with the Developer Tools debugging protocol.
GetDownloadableFiles()
Retrieves the downloadable files.
public IReadOnlyList<string> GetDownloadableFiles()
Returns
- IReadOnlyList<string>
A read-only list of file names available for download.