How to handle the “unexpected alert open”?

后端 未结 7 553
耶瑟儿~
耶瑟儿~ 2020-12-28 18:07

I got an issue with Selenium throwing timeout exception because of a pop up window

  unexpected alert open
  not provide any stacktrace inform         


        
7条回答
  •  悲哀的现实
    2020-12-28 18:28

    Try this,

    public boolean isAlertPresent() {
    
        boolean presentFlag = false;
    
        try {
    
            // Check the presence of alert
            Alert alert = driver.switchTo().alert();
            // Alert present; set the flag
            presentFlag = true;
            // if present consume the alert
            alert.accept();
            //( Now, click on ok or cancel button )
    
        } catch (NoAlertPresentException ex) {
            // Alert not present
            ex.printStackTrace();
        }
    
        return presentFlag;
    }
    

    I hope this will helpful to you.

提交回复
热议问题