Skip to content

Interacting with Alerts

StageZero follows a similar approach to interacting with alerts to the likes of Playwright and Puppeteer. You can subscribe to the OnAlert event listener available in the IDriverWeb object. This allows you to have clear, concise alert handling and reduces the requirement for having to wait for an alert to appear in the browser.

Usage

var driver = DriverBuilder.Create(new WebDriverOptions());
driver.OnAlert += async (_, alert) =>
{
// Handle any alert based actions here.
};

⚠️ Precautions

You must ensure that you handle the alert directly in the OnAlert event handler. If you do not call either Dismiss or Confirm your tests will hang.

Confirming an alert

driver.OnAlert += async (_, alert) =>
{
await alert.Confirm();
};

Dismissing an alert

driver.OnAlert += async (_, alert) =>
{
await alert.Dismiss();
};

Getting alert text

driver.OnAlert += async (_, alert) =>
{
Console.WriteLine(alert.Message);
await alert.Dismiss();
};