Skip to content

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

Here are some common element interaction use cases driven by StageZero.

Getting an element

var element = await Driver.GetElement("#element");

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

var buttonElement = await Driver.GetElement("#btn-element");
await buttonElement.Click();

Right clicking an element

var rightClickElement = await Driver.GetElement("#right-click-element");
await rightClickElement.RightClick();

Double clicking an element

var buttonElement = await Driver.GetElement("#btn-element");
await buttonElement.DoubleClick();

Typing text

var inputElement = await Driver.GetElement("#input-element");
await inputElement.Type("Just some text");

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

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

var selectElement = await Driver.GetElement("#select-element");
await selectElement.SelectOption(1);

Scrolling to an element

var scrollContainer = await Driver.GetElement("#scroll-container");
var scrolledToElement = await scrollContainer.ScrollTo("#scrolled-to-element");

Keyboard shortcuts

var shortcutElement = await Driver.GetElement("#shortcut-element");
await shortcutElement.PressKeys(Keys.Control | Keys.S);