Interacting with Elements
As we all know, on the modern web you can interact with elements in various different ways.
That’s pretty neat, but can sometimes be tricky to test! StageZero
aims to remove that concern for you, so all you’re thinking about is how to write your test.
Element interactions
Section titled “Element interactions”Here are some common element interaction use cases driven by StageZero
.
Getting an element
Section titled “Getting an element”var element = await Driver.GetElement("#element");
Getting elements
Section titled “Getting elements”Similar to the above snippet, you are also able to get a collection of HTML elements using:
var elements = await Driver.GetElements("#element");
Clicking an element
Section titled “Clicking an element”var buttonElement = await Driver.GetElement("#btn-element");await buttonElement.Click();
Right clicking an element
Section titled “Right clicking an element”var rightClickElement = await Driver.GetElement("#right-click-element");await rightClickElement.RightClick();
Double clicking an element
Section titled “Double clicking an element”var buttonElement = await Driver.GetElement("#btn-element");await buttonElement.DoubleClick();
Typing text
Section titled “Typing text”var inputElement = await Driver.GetElement("#input-element");await inputElement.Type("Just some text");
Holding an element
Section titled “Holding an element”var elementToHold = await Driver.GetElement("#hold-element");var timeToHold = TimeSpan.FromSeconds(1);
await elementToHold.ClickAndHold(timeToHold);
Selecting an option from a dropdown
Section titled “Selecting an option from a dropdown”Selecting an option based on its text contents
Section titled “Selecting an option based on its text contents”var selectElement = await Driver.GetElement("#select-element");await selectElement.SelectOption("Value 1");
Selecting an option based on its index
Section titled “Selecting an option based on its index”var selectElement = await Driver.GetElement("#select-element");await selectElement.SelectOption(1);
Scrolling to an element
Section titled “Scrolling to an element”var scrollContainer = await Driver.GetElement("#scroll-container");var scrolledToElement = await scrollContainer.ScrollTo("#scrolled-to-element");
Keyboard shortcuts
Section titled “Keyboard shortcuts”var shortcutElement = await Driver.GetElement("#shortcut-element");await shortcutElement.PressKeys(Keys.Control | Keys.S);