Auto test executions stops and an error is displayed: WebDriver Bidi command "browsingContext.handleUserPrompt" failed with error: no such alert

I encountered this error during our test execution and I cannot find an appropriate fix on the WebdriverIO documentation
Error: WebDriver Bidi command "browsingContext.handleUserPrompt" failed with error: no such alert - No dialog is showing
Framework: WebdriverIO v9
I found this similar issue posted here and I tried to implement the explicit dialog listener of wdio as posted here but the error still persist on my end.
Any help would be appreciated.
Answer
This error typically means that WebdriverIO attempted to interact with an alert that doesn't exist in the browser. This usually happens when the alert was already dismissed or accepted before your test tried to interact with it.
--
Something I would recommend to you is to make sure the alert actually appears before trying to handle it. You can use a waitUntil
or appropriate check.
await browser.waitUntil(async () => {
try {
await browser.getAlertText();
return true;
} catch (err) {
return false;
}
}, {
timeout: 5000,
timeoutMsg: 'Expected alert to be present within 5s'
});
// Now it's safe to accept or dismiss
await browser.acceptAlert(); // or dismissAlert()
Enjoyed this question?
Check out more content on our blog or follow us on social media.
Browse more questions