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
optionsDriverOptionsAn 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
capabilitiesICapabilitiesAn 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
commandExecutorICommandExecutorAn ICommandExecutor object which executes commands for the driver.
capabilitiesICapabilitiesAn 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
remoteAddressUriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
optionsDriverOptionsAn 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
remoteAddressUriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
capabilitiesICapabilitiesAn 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
remoteAddressUriURI containing the address of the WebDriver remote server (e.g. http://127.0.0.1:4444/wd/hub).
capabilitiesICapabilitiesAn ICapabilities object containing the desired capabilities of the browser.
commandTimeoutTimeSpanThe 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
fileNamestringThe name of the file to be downloaded.
targetDirectorystringThe target directory where the file should be downloaded to.
Exceptions
- ArgumentNullException
If
targetDirectoryis null.
FindElementByClassName(string)
Finds the first element in the page that matches the CSS Class supplied
public IWebElement FindElementByClassName(string className)
Parameters
classNamestringclassName 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
cssSelectorstringThe 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
idstringID 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
linkTextstringLink 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
namestringName 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
partialLinkTextstringpart 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
tagNamestringDOM 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
xpathstringxpath 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
classNamestringCSS 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
cssSelectorstringThe 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
idstringID 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
linkTextstringLink 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
namestringName 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
partialLinkTextstringpart 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
tagNamestringDOM 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
xpathstringxpath 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
optionsDevToolsOptions
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.