acceptAlert
Accept the user prompt (alert, confirm or prompt) that is open in this
browsing context. Prompts in other tabs stay open.
WebdriverIO dismisses prompts automatically unless something listens to the
dialog event, so register a listener first. In a listener you can also
answer with the dialog object directly.
Usage
const context = await browser.url('https://webdriver.io')
await context.acceptAlert(userText)
Parameters
| Name | Type | Details |
|---|---|---|
userTextoptional | string | text to enter into a prompt |
Example
acceptAlert.js
it('accepts a confirm in a background tab', async () => {
browser.on('dialog', () => {}) // keep prompts open
await browser.url('https://webdriver.io')
const tab = await browser.newWindow('https://webdriver.io', { type: 'tab' })
const opened = new Promise((resolve) => browser.once('dialog', resolve))
await tab.execute(() => setTimeout(() => window.confirm('Continue?')))
await opened
await tab.acceptAlert()
})