0

I have written a code to find if any alert there if so click on alert and continue else continue the flow using below code:

fd.findElement(By.name("submit")).click();

    String str="";
    Alert alert =null;
    try{
        alert = fd.switchTo().alert();
        if(alert!=null && !"".equals(alert)){
            str= alert.getText();
            System.out.println("alert there");
        }
    }catch(NoAlertPresentException e){
        e.printStackTrace();
        str = "";
        System.out.println("no alert");
    }
    System.out.println("print alert::::--->:"+alert);

    System.out.println("print alert:str--->"+str);

my flow is working but in console am getting an error stating:

No alert is present (WARNING: The server did not provide any stacktrace information)

How do I resolve this issue?

JRodDynamite
  • 12,325
  • 5
  • 43
  • 63
Aditya
  • 1
  • 1
  • 3
  • Try searching for existing q&a first - http://stackoverflow.com/questions/7722940/no-alert-is-present-no-modal-dialog-found-webdriver-unable-to-catch-js-error – Germann Arlington Oct 22 '15 at 18:48
  • Possible duplicate of [How to check if an alert exists using WebDriver?](http://stackoverflow.com/questions/11467471/how-to-check-if-an-alert-exists-using-webdriver) – JeffC Oct 22 '15 at 22:31

0 Answers0