Wednesday, 12 April 2023

How to close a browser alert with webdriver

A web driver test produces a browser alert: Do you want to leave this page? Cancel | Continue. None of the following commands selects the Continue button.

await browser.acceptAlert()
await browser.pressKeyCode(13) // 13 = Enter key
await browser.confirm()

These have been tried in the content of the afterEach :

describe('xxx', () => {
    afterEach(async () => {
        await browser.execute('window.localStorage.clear()');
        await browser.deleteAllCookies()
        await browser.execute('sessionStorage.clear()')
        await browser.refresh()
        // await browser.acceptAlert() // not working
        // await browser.pressKeyCode(13) // not working
        // await browser.confirm() // not working
        await browser.pause(1000)
    });

Using web driver v7.

This is the alert:

enter image description here

Is this an OS alert rather than a native browser alert?

This answer is not applicable.



from How to close a browser alert with webdriver

No comments:

Post a Comment