
Var popuResult = confirm("Confirm pop up with OK and Cancel button") Var person = prompt("Do you like Edureka?", "Yes/No") Click on the button, “Display Alert” which generates the alert box and then click on OK(accept) button.Launch the web browser and open the webpage.
#SELENIUM POPUP WINDOW HOW TO#
In this scenario, we will consider using our own Edureka demo site to illustrate how to handle alerts in Selenium Webdriver. In order to understand how to handle the alerts in Selenium, let’s work on the demo. driver.switchTo().alert().sendKeys("Text") This is called when you want to send some data to alert box. This method is called to capture the alert message. This method is called when you click on the ‘OK’ button of the alert. This method is called when the ‘Cancel’ button is clicked in the alert box. Let us learn about these Alert Interface Methods. Once you switch the control from the current browser to the alert window, you can use the Alert Interface methods to perform the required actions such as accepting the alert, dismissing the alert, getting the text from the alert window, writing some text on the alert window, etc.,
#SELENIUM POPUP WINDOW DRIVER#
While running the test script, the driver control will be on the browser even after the alert is generated. I will help you understand how this can be done. Handling the alerts is a tricky task but, Selenium Webdriverprovides functionalities that make this process way too easy. How to handle Alerts in Selenium WebDriver? Once you are clear with the different types of alerts, it will be easy to understand how to handle these alerts. In order to accept the alert, you can use the Alert.accept()and to dismiss, use Alert.dismiss() Confirmation Alert: This type of alert comes with an option to accept or dismiss the alert.

You can use the sendKeys() method to type some text in the Prompt alert box. This is specifically used when some input is required from the user. Prompt Alert: In prompt alerts, you get an option to add a text field to the alert box.
#SELENIUM POPUP WINDOW CODE#
The following code will read the text from the Alert and then accept the alert.Īlert simpleAlert = driver.switchTo().alert() The very first alert on the test page is a simple alert. They are mainly used to display some information to the user.


For further details, you can refer to the Selenium Certification. Through the medium of this blog on how to handle alerts in Selenium, I will help you understand all about alerts and pop-ups in Selenium. Dealing with these alerts while testing an application is too tedious. Testing a web page requires a specific set of rules to be followed but, when you tend to miss it, the system will end up throwing an alert.
