org.openqa.selenium.UnhandledAlertException: unexpected alert open

后端 未结 10 743
情歌与酒
情歌与酒 2020-11-30 06:33

I am using a Chrome Driver and trying to test a webpage.

Normally it runs fine, but sometimes I get exceptions:

 org.openqa.selenium.UnhandledAlertE         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 07:22

    Following is working for me

        private void acceptSecurityAlert() {
    
        Wait wait = new FluentWait(driver).withTimeout(10, TimeUnit.SECONDS)          
                                                                .pollingEvery(3, TimeUnit.SECONDS)          
                                                                .ignoring(NoSuchElementException.class);    
        Alert alert = wait.until(new Function() {       
    
            public Alert apply(WebDriver driver) {
    
                try {
    
                    return driver.switchTo().alert();
    
                } catch(NoAlertPresentException e) {
    
                    return null;
                }
            }  
        });
    
        alert.accept();
    }
    

提交回复
热议问题