Tuesday, 3 December 2013

How to handle java script alert using WebDriver

WebDriver supports handling  JavaScript alerts using Alert interface.

          // Bring control on already opened alert
               Alert alert = driver.switchTo().alert();

          // Get the text/message of the alert or prompt
               alert.getText(); 
         
         // Click ok button of alert
              alert.accept();

         // Click Cancel button of alert

              alert.dismiss();

No comments:

Post a Comment