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.

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

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

Similar to the above snippet, you are also able to get a collection of HTML elements using:

var elements = await Driver.GetElements("#element");
var buttonElement = await Driver.GetElement("#btn-element");
await buttonElement.Click();
var rightClickElement = await Driver.GetElement("#right-click-element");
await rightClickElement.RightClick();
var buttonElement = await Driver.GetElement("#btn-element");
await buttonElement.DoubleClick();
var inputElement = await Driver.GetElement("#input-element");
await inputElement.Type("Just some text");
var elementToHold = await Driver.GetElement("#hold-element");
var timeToHold = TimeSpan.FromSeconds(1);
await elementToHold.ClickAndHold(timeToHold);

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");
var selectElement = await Driver.GetElement("#select-element");
await selectElement.SelectOption(1);
var scrollContainer = await Driver.GetElement("#scroll-container");
var scrolledToElement = await scrollContainer.ScrollTo("#scrolled-to-element");
var shortcutElement = await Driver.GetElement("#shortcut-element");
await shortcutElement.PressKeys(Keys.Control | Keys.S);