Tuesday, 8 April 2014

Working with Alert and Pop up window using selenium WebDriver



In web application mostly we see below two types of pop-ups,

1. alerts   ( only "OK" button )
2. confirm popup ( Both "OK" and "CANCEL" button)

Handling both alerts & confirms popup WebDriver has a Alert interface. Using WebDriver you can click on OK or Cancel button and also can get

alert message also to verify.

Logic

//First we need switch the control to alert.
       Alert alert = driver.switchTo().alert();
//Getting alert text
       alert.getText();
//Click on OK
       alert.accept();
//Click on Cancel
      alert.dismiss();

No comments:

Post a Comment