What is the best way to handle a Javascript popup using Selenium Webdriver?

selenium

Can anyone suggest what is the best way to handle a JavaScript Pop-up using Selenium Webdriver?

1
Answers

Replies

The simplest way to handle a Javascript popup is by using the Alert interface. In order to access the popup/alert dialog in Selenium webdriver, the following code has to be used.


webDriver.switchTo().alert()


The alert interface provides the following methods to handle/interact with the javascript dialogs/popup


1.accept() : To accept an alert/popup
2.dismiss() : To decline an popup/alert
3.getText(): To get the text written on the popup/alert
4.sendKeys (Keys to enter): To enter some text on the popup/alert’s input box.

 
 

If you want to unleash your potential in this competitive field, please visit the selenium course page for more information, where you can find the selenium tutorials and selenium frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
Protected by Astra Security