Selenium WebDriver how to close browser popup

前端 未结 9 1063
悲&欢浪女
悲&欢浪女 2020-11-27 18:29

I am writing tests for a web App using selenium webDriver and came across a scenario where when I try to close the browser I get a popup saying \"Are you sure? The page is a

9条回答
  •  时光取名叫无心
    2020-11-27 19:01

    You need to handle the unexpected alerts using try catch blocks. Put your code in try block and catch the 'UnhandledAlertException'

    Example:

    try{
         .....
         .....
         code here
    }catch(UnhandledAlertException e ){
        driver.switchto().alert().dismiss();
    }
    

提交回复
热议问题