Alert & Popup Handling in Selenium WebDriver

What is Alert?

Alert is a small message box which displays on-screen notification to give the user some kind of information or ask for permission to perform certain kind of operation. It may be also used for warning purpose.
Here are few alert types:
1) Simple Alert
This simple alert displays some information or warning on the screen.
2) Prompt Alert.
This Prompt Alert asks some input from the user and selenium webdriver can enter the text using sendkeys(" input…. ").
3) Confirmation Alert.
This confirmation alert asks permission to do some type of operation.

How to handle Alert in Selenium WebDriver

Alert interface provides the below few methods which are widely used in Selenium Webdriver.
1) void dismiss() // To click on the 'Cancel' button of the alert.
driver.switchTo().alert().dismiss();
2) void accept() // To click on the 'OK' button of the alert.
driver.switchTo().alert().accept();
3) String getText() // To capture the alert message.
We can easily switch to alert from the main window by using Selenium's .switchTo() method.

Comments

Post a Comment

Popular posts from this blog

Handling Dynamic Web Tables Using Selenium WebDriver

Verify Specific Position of an Element

Read it out for TESTNG before going for an iterview