How to check if an alert exists using WebDriver?

后端 未结 9 1764
名媛妹妹
名媛妹妹 2020-12-01 09:09

I need to check the existence of Alert in WebDriver.

Sometimes it pops up an alert but sometimes it will not pop up. I need to check if the alert exists first, then

9条回答
  •  悲哀的现实
    2020-12-01 09:37

    public boolean isAlertPresent() 
    { 
        try 
        { 
            driver.switchTo().alert(); 
            return true; 
        }   // try 
        catch (NoAlertPresentException Ex) 
        { 
            return false; 
        }   // catch 
    }   // isAlertPresent()
    

    check the link here https://groups.google.com/forum/?fromgroups#!topic/webdriver/1GaSXFK76zY

提交回复
热议问题