top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can we handle web based pop up in Selenium?

+1 vote
400 views
How can we handle web based pop up in Selenium?
posted Oct 25, 2016 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface. There are the four methods that we would be using along with the Alert interface.

void dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop up window appears.
void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window appears.
String getText() – The getText() method returns the text displayed on the alert box.
void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.

Syntax:

// accepting javascript alert

Alert alert = driver.switchTo().alert();
alert.accept();
answer Nov 2, 2016 by Manikandan J
...