Unable to handle an alert on a new tab (redirected) in WebdriverIO

15 views Asked by At

I'm new to WDIO and I'm trying to use it to automate some test cases. I'm stuck trying to handle an alert on a redirected page.

Upon logging in, the system redirects me to the landing page on a new tab in the browser. However, before loading the landing page you have to accept two alerts. From what I understand, the alerts are stopping the execution before I can switch to the new window (the one that has the landing page and the alerts) so I can't use .acceptAlert() because WDIO is focused on a different window. How can I solve this? Thanks in advance.

Code

await dashboard.click()
await browser.pause(1000)    
const handles = await browser.getWindowHandles() <-- this is where it gets stuck, waiting for me to accept the alert
let NewWindow = handles[2]
await browser.pause(1000)
await browser.switchToWindow(NewWindow)
const title = await browser.getTitle()

Log (until it gets stuck)

`[0-0] 2024-03-11T22:09:34.749Z INFO webdriver: COMMAND elementClick("f.84EF803C732F3DCB0D6C3A4B20FE2274.d.4654696486DB094412E4D1078C4FE566.e.39")
[0-0] 2024-03-11T22:09:34.749Z INFO webdriver: [POST] http://0.0.0.0:57281/session/73a89f5c8a69df76ab08e4d7f1f86d94/element/f.84EF803C732F3DCB0D6C3A4B20FE2274.d.4654696486DB094412E4D1078C4FE566.e.39/click
[0-0] 2024-03-11T22:09:34.853Z INFO webdriver: RESULT null
[0-0] 2024-03-11T22:09:35.868Z INFO webdriver: COMMAND getWindowHandles()
[0-0] 2024-03-11T22:09:35.869Z INFO webdriver: [GET] http://0.0.0.0:57281/session/73a89f5c8a69df76ab08e4d7f1f86d94/window/handles`
0

There are 0 answers