sitespeedio / sitespeed.io

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.
https://www.sitespeed.io/
MIT License
4.75k stars 602 forks source link

Handle Alert box in sitespeed.io #4087

Closed Pearlking311 closed 9 months ago

Pearlking311 commented 9 months ago

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)
Pearlking311 commented 9 months ago

Similar example

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

image
soulgalore commented 9 months ago

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

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

Pearlking311 commented 9 months ago

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)

soulgalore commented 9 months ago

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?

Pearlking311 commented 9 months ago

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

soulgalore commented 9 months ago

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

Pearlking311 commented 9 months ago

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