org.openqa.selenium.UnhandledAlertException: unexpected alert open

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

    I was facing the same issue and I made this below changes.

    try {
        click(myButton);
    } catch (UnhandledAlertException f) {
        try {
            Alert alert = driver.switchTo().alert();
            String alertText = alert.getText();
            System.out.println("Alert data: " + alertText);
            alert.accept();
        } catch (NoAlertPresentException e) {
            e.printStackTrace();
        }
    }
    

    It worked amazingly.

提交回复
热议问题