Skip to content

Executing JavaScript

Sometimes it’s necessary to execute JavaScript directly in the browser from your tests. StageZero supplies a variety of utility commands to achieve this across our support WebDrivers.

Running JavaScript

Test.cs
var js = "console.log('Hello world!');";
await driver.Document().ExecuteJavaScript(js);

Retrieving an object using JavaScript

Test.cs
var js = "return document.location.href;";
var href = await driver.Document().ExecuteJavaScript<string>(js);