org.openqa.selenium.UnhandledAlertException: unexpected alert open

后端 未结 10 751
情歌与酒
情歌与酒 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:28

    Is your switch to alert within a try/catch block? You may also want to add a wait timeout to see if the alert shows up after a certain delay

    try {
        // Add a wait timeout before this statement to make 
        // sure you are not checking for the alert too soon.
        Alert alt = driver.switchTo().alert();
        alt.accept();
    } catch(NoAlertPresentException noe) {
        // No alert found on page, proceed with test.
    }
    

提交回复
热议问题