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