Hello Dimple, the simplest way to handle JavaScript popup/alert using selenium is by using the Alert interface. To access the popup/alert dialog in Selenium Webdriver, use the following line of code:
webDriver.switchTo().alert()
The alert interface provides following methods to handle/interact with such Javascript popups/dialogs:
- accept(): To accept an popup/alert
- dismiss(): To decline an popup/alert
- getText(): To get the text written on the popup/alert
- sendKeys(keysToEnter): To enter some text on the popup/alert's input box