Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get text from the alert box

I need to grab a text from the alert box shown below. This alert box appears hovering above the url bar. Below is an example of my framework assertion:

verifyDisplay("'"+ driver.switchTo().alert().getText() + "'", By.xpath("xpath").

I am not sure, how to grab xpath, id, name of this alert box, since there is none.

Any help is greatly appreciated.

enter image description here

like image 544
familyGuy Avatar asked Dec 05 '22 23:12

familyGuy


1 Answers

There is a method in Alert interface which gives you the text of the alert box message. As below:

Alert alert = driver.switchTo().alert();
alert.getText();

Alert API javadoc

Let me know if you need further help.

like image 155
Mrunal Gosar Avatar answered Jun 14 '23 11:06

Mrunal Gosar