Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text from leave site alert using JavaScript? [closed]

Is there any way to get the text from an alert in JavaScript?

Below I have attached the screenshot of an alert.

Actually I am trying to automate a website using selenium and java and selenium isn't able to handle such alert.

I wonder whether the JavaScript has solution to such alerts.

I am not aware of JavaScript syntax and code styling so posting only a question. Please excuse me for this.

driver.switchTo.alert().getText() 

only works for if it is a JS alert,if it is browser alert then it doesn't work

ALERT EXAMPLE:

enter image description here

like image 970
Good Vibes Avatar asked Dec 18 '25 05:12

Good Vibes


1 Answers

You should try this, with Selenium:

Alert alert = driver.switchTo().alert();
alert.getText();
like image 173
Mate Mrše Avatar answered Dec 19 '25 19:12

Mate Mrše



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!