Skip to main content

dismissAlert

Dismiss the user prompt (alert, confirm or prompt) that is open in this browsing context, like pressing "Cancel". Prompts in other tabs stay open.

WebdriverIO dismisses prompts automatically unless something listens to the dialog event, so register a listener first when you want to answer yourself.

Usage​

const context = await browser.url('https://webdriver.io')
await context.dismissAlert()

Example​

dismissAlert.js
it('dismisses a confirm in one tab only', async () => {
browser.on('dialog', () => {}) // keep prompts open
const page = await browser.url('https://webdriver.io')

const opened = new Promise((resolve) => browser.once('dialog', resolve))
await page.execute(() => setTimeout(() => window.confirm('Leave?')))
await opened
await page.dismissAlert()
})

Welcome! How can I help?

WebdriverIO AI Copilot