sitespeedio/sitespeed.io

Handle Alert box in sitespeed.io

Pearlking311 opened this issue · 7 comments

Your question

Need help on handling Alert box. I have tried with

const Alert = seleniumWebdriver.Alert;
await Alert.accept();

But getting below mentioned error.

ERROR: Failed waiting on page to finished loading, timed out after 120000 ms UnexpectedAlertOpenError: unexpected alert open: {Alert text : Are you sure you want to delete 1 record(s)?}

(Session info: chrome=121.0.6167.161)

(Session info: chrome=121.0.6167.161)

at Object.throwDecodedError (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\error.js:524:15)

at parseHttpResponse (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\http.js:601:13)

at Executor.execute (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\http.js:529:28)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

at async Driver.execute (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\webdriver.js:745:17)

[2024-02-13 16:44:55] ERROR: UrlLoadError: Failed waiting on page to finished loading, timed out after 120000 ms

at SeleniumRunner._waitOnPageCompleteCheck (file:///C:/Users/mjs/AppData/Roaming/npm/node_modules/sitespeed.io/node_modules/browsertime/lib/core/seleniumRunner.js:210:15)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

at async module.exports (D:\test\Script\SC01_Contact_Selenium.js:149:3)

at async file:///C:/Users/mjs/AppData/Roaming/npm/node_modules/sitespeed.io/node_modules/browsertime/lib/core/engine/run.js:4:7

at async Iteration.run (file:///C:/Users/mjs/AppData/Roaming/npm/node_modules/sitespeed.io/node_modules/browsertime/lib/core/engine/iteration.js:244:9)

at async Engine.runByScript (file:///C:/Users/mjs/AppData/Roaming/npm/node_modules/sitespeed.io/node_modules/browsertime/lib/core/engine/index.js:304:20)

at async analyzeUrl (file:///C:/Users/mjs/AppData/Roaming/npm/node_modules/sitespeed.io/lib/plugins/browsertime/analyzer.js:190:19)

at async BrowsertimePlugin.processMessage (file:///C:/Users/mjs/AppData/Roaming/npm/node_modules/sitespeed.io/lib/plugins/browsertime/index.js:173:26)

Similar example

Browser: Chrome
URL: https://www.demoblaze.com/prod.html?idp_=1#
Action: Add product to cart

image

Hi @Pearlking311 I checked the Selenium NodeJS documentation and this should do the trick:

await context.selenium.driver.switchTo().alert().accept();

Hi @soulgalore , It doesn't works for me. Attaching the script for your reference.
Add.txt

Error:
ERROR: Failed waiting on page to finished loading, timed out after 120000 ms UnexpectedAlertOpenError: unexpected alert open: {Alert text : Product added}
(Session info: chrome=121.0.6167.161)
(Session info: chrome=121.0.6167.161)
at Object.throwDecodedError (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\error.js:524:15)
at parseHttpResponse (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\http.js:601:13)
at Executor.execute (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\http.js:529:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Driver.execute (C:\Users\mjs\AppData\Roaming\npm\node_modules\sitespeed.io\node_modules\selenium-webdriver\lib\webdriver.js:745:17)

It works when I tested on your example on https://www.demoblaze.com/prod.html?idp_=1# ? Maybe it's something else, can you share the full example then so I can help you?

Hi @soulgalore I have attached full script on above comments as txt file. Attaching here also for your reference
Add.txt

Hi @Pearlking311 so I made one change when you click and it works for me, hope it works for you too.

 // await commands.click.byXpathAndWait('//a[text()="Add to cart"]');
await commands.mouse.singleClick.byLinkText('Add to cart');

The ...AndClick means that it's waiting for a page navigation. When I try debug scripts I try to follow these things: https://www.sitespeed.io/documentation/sitespeed.io/scripting/tutorial-07-Debugging-Scripts.html

@soulgalore Thanks for your support. It works. Closing the issue.