WebDriverWaitExtensions is a C# library that provides extension methods for Selenium WebDriver's WebDriverWait class, simplifying the process of waiting for specific conditions in web automation. It includes detailed error messages and supports the use of Condition objects for assertions.
License
—
Deps
1
Install Size
—
Vulns
✓ 0
Published
Oct 2, 2024
$ dotnet add package WebDriverWaitExtensionsWebDriverWait Extensions is a C# library that provides extension methods for the WebDriverWait class in Selenium WebDriver. It is designed to simplify the process of waiting for certain conditions to be met in a web page when automating browser interactions.
There has been a lot of focus on the returned error messages when the condition isn't met which will even include the name of the parameter. This is especially helpful when using the page object model.
var signUpButton = By.Id("sign-up");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.UntilElement().IsVisible(signUpButton);
In the above example the element was found but was not visible which returned the follow error:
Locator Name: 'signUpButton'
Locator: 'By.Id: sign-up'
Displayed: False
Enabled: True
Location: {X=90,Y=110}
Selected: False
Size: {Width=211, Height=66}
TagName: a
Text: ''
You can use the 'out' keyword to return a Condition object which will contain the condition result and will contain the
error if one occured. This allows you to use these wait conditions as asserts.
If we had a method to check if an element is visible for use in an assert, and we wanted to ensure it waits long enough to become visible, it would either always return true or throw an exception. By using the Condition object, we can suppress the exception and allow the condition to run and return the result.
wait.UntilElement().IsVisible(signUpButton, out var condition);
Assert.That(condition.Result, Is.True, condition.Error);
The library provides the following features:
For more detailed documentation, please visit the wiki.
If you find this project useful and would like to support its development, please consider making a donation.
Your contributions help to improve and maintain the project.
Donate via PayPal