# 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](/docs/api/dialog.md) directly.

## Usage[​](#usage "Direct link to Usage")

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

await context.acceptAlert(userText)
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name                       | Type     | Details                       |
| -------------------------- | -------- | ----------------------------- |
| `userText`<br />*optional* | `string` | text to enter into a `prompt` |

## Example[​](#example "Direct link to 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()

})
```
