Friday, January 17, 2014

Wait For Alert message, read and Print


package Sample;
import org.openqa.selenium.Alert;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;

public class WaitForAlertMsg extends Login
{
  //public static WebDriver driver;
       public static void waitForAlert(WebDriver driver) throws InterruptedException
       {
          int i=0;

          while(i++<5)

          {
               try
               {
                   Alert alert = driver.switchTo().alert();
                   String Alerttext = alert.getText();
                   System.out.println("Alerttext");
                   alert.accept();
                   break;
               }
               catch(NoAlertPresentException e)
               {
                 Thread.sleep(2000);
                continue;
               }
          }
       }

}
 
 

Note: Use this method every where where ever you want to use.


WaitForAlertMsg.waitForAlert(driver);

 

No comments:

Post a Comment

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...