Helper methods interacting with web elements. Adds extension methods to automatically wait for elements to be on screen before attempting an action.
License
—
Deps
2
Install Size
—
Vulns
✓ 0
Published
Oct 26, 2023
$ dotnet add package Selenium.Ui.Test.HelperBasic helper methods for selenium. Includes methds for initializing a driver and extension methods with automatic wait times for interacting with web elements.
Waits for a single element to be displayed and returns it.
var elementLocator = By.Id("elementId");
elementLocator.GetElement(driver);
Waits for elements to be displayed and returns them. Optionally, can wait for a specific number of elements to be displayed before retuning.
var elementsLocator = By.CssSelector(".list-item");
var elements = elementLocator.GetElements(driver);
// If expected number of elements is known, we can optionally wait for n number of elements to be displayed.
var elementsLocator = By.CssSelector(".list-item");
var elements = elementLocator.GetElements(driver, waitForElementCount: 10);
// Returns an element with specific text. For example to extract an item from a list where text = "Hello World"
var elementsLocator = By.CssSelector(".list-item");
var element = elementLocator.GetElementWithText(driver, "Hello World");
Waits for element to be displayed and performs click.
var elementLocator = By.Id("elementId");
elementLocator.Click(driver);
Waits for text field/area to be displayed and enters text.
var elementLocator = By.Id("elementId");
elementLocator.SendKeys(driver, "value");
Waits for text field/area to be displayed and clears text.
var elementLocator = By.Id("elementId");
elementLocator.Clear(driver);
Waits for element to be displayed and returns the text value of the element.
var elementLocator = By.Id("elementId");
var text = elementLocator.GetText(driver);
Waits for text field/area to be displayed and returns the current value entered.
var elementLocator = By.Id("elementId");
var value = elementLocator.GetValue(driver);
The default wait time for finding elements is set to 30 seconds. This value can be adjusted individually on each action method.
Add a new file to the root of your project called "testsettings.json" and a new timeout as follows.
elementLocator.SendKeys(driver, value, 20000); // Sets timeout on this step only to 20 seconds