# getAlertText

Get the message of the user prompt (`alert`, `confirm` or `prompt`) that is open in this browsing context. Rejects with `no such alert` when none is open.

WebdriverIO dismisses prompts automatically unless something listens to the `dialog` event, so register a listener first.

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

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

await context.getAlertText()
```

## Example[​](#example "Direct link to Example")

getAlertText.js

```
it('reads the message of a prompt', 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.alert('Saved')))

    await opened

    console.log(await page.getAlertText()) // outputs: "Saved"

    await page.acceptAlert()

})
```

## Returns[​](#returns "Direct link to Returns")

* **\<string>** **`return`:** the prompt message
