![]() |
VOOZH | about |
dotnet add package WebDriver.Extensions --version 1.1.4
NuGet\Install-Package WebDriver.Extensions -Version 1.1.4
<PackageReference Include="WebDriver.Extensions" Version="1.1.4" />
<PackageVersion Include="WebDriver.Extensions" Version="1.1.4" />Directory.Packages.props
<PackageReference Include="WebDriver.Extensions" />Project file
paket add WebDriver.Extensions --version 1.1.4
#r "nuget: WebDriver.Extensions, 1.1.4"
#:package WebDriver.Extensions@1.1.4
#addin nuget:?package=WebDriver.Extensions&version=1.1.4Install as a Cake Addin
#tool nuget:?package=WebDriver.Extensions&version=1.1.4Install as a Cake Tool
I created this repository to help with Selenium testing.
I found there were some problems with using the built in tools.
The current tooling seems to throw exceptions a lot when the element can't be found. This is due to the page not loading fully, or not being visible.
So, these extensions use the catch Exception to catch all exceptions raised by the find methods.
If you need the exceptions to be raised, then this extension is not for you.
There is a way to try and find an element using a class called WebDriverWait. However, I found that this still threw exceptions. So, I have written this extension to wrap a do while loop around the try catch block.
public static IWebElement SafeFindElement(this IWebDriver driver, By by, int timeOutInSeconds = 0, Func<IWebElement, IWebElement> elementCheckFunc = null)
public static IReadOnlyCollection<IWebElement> SafeFindElements(this IWebDriver driver, By by, int timeOutInSeconds = 0)
The object that we are using for testing.
The By parameter we are using for the search.
The time out in seconds that the process will run for while it is attempting to find the element(s). If the time runs out, and the element(s) still hasn't been found, then it will return null, and not throw an exception.
This function is what you would like to run against the element found. As long as it returns an IWebElement.
You would use it to limit the element further. You might not want the element that has been found, as it is not enabled, or displayed.
Here are some examples of how to use the element. They are, mostly, taken from the unit test project.
var result = _driver.SafeFindElement(By.Id("banana"));
var result = _driver.SafeFindElement(By.Id("banana"), 5);
var result = _driver.SafeFindElement(By.Id("banana"), 0, (element) => element.Displayed ? element : null);
var result = _driver.SafeFindElement(By.Id("banana"), 5, (element) => element.Displayed ? element : null);
var result = _driver.SafeFindElement(By.Id("banana"), 5, (element) => (element.Displayed && element.Enabled) ? element : null);
var result = _driver.SafeFindElements(By.Id("banana"));
var result = _driver.SafeFindElements(By.Id("banana"), 5);
To keep the methods names the same as the Selenium.WebDriver methods, an issue was raised on GitHub. This has been fixed.
The following methods are now obsolete and will be removed in a later version of the library.
SafeGetElementSafeGetElements| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
1.1.4 -
-> Support dotnet 10.
-> Use Nerdbank.GitVersion.
-> Use `.snlx` solution file style.
1.0.8 -
-> Support dotnet 9.0
-> Update NuGet packages
1.0.7 -
-> Update NuGet packages due to vulnerability.
-> Support dotnet 7.0
-> Support dotnet 8.0
-> Remove support for dotnet versions that are out of support. Supporting dotnet 6.0 and above.
1.0.5 -
-> Update vulnerable packages identified by Snyk
* Newtonsoft.Json v9.0.1 - v13.0.1
* System.Net.Http v4.3.0 - v4.3.4
* System.Text.RegularExpressions v4.3.0 - v4.3.1
1.0.4 -
-> Skipped due to failed build
1.0.3 -
-> Add support for dotnet 5.0
-> Add support for dotnet 6.0
-> Updated Selenium package to v4
1.0.1.3 -
-> Changed name of method.
-> Set original method as obsolete
-> "Get" method will be removed in v1.1.0
1.0.0 -
-> Initial version