Selenium WebDriver how to close browser popup

前端 未结 9 990
悲&欢浪女
悲&欢浪女 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条回答
  • Not sure what is the structure of the popup that you have used. Here are a few that may work for you if you have used either of as to popup.

    If its an alert. you can try:

    driver.SwitchTo().Alert()
    

    If its a window that pops up then:

    driver.SwitchTo().Window(<windowname>)
    

    For iFrame:

    driver.SwitchTo().Frame("iFrmLinks")
    

    Once you get through either of the three then you can access all its internal elements.

    Regards Tahir

    0 讨论(0)
  • 2020-11-27 19:06
     ( ( JavascriptExecutor ) _driver )
                .executeScript( "window.onbeforeunload = function(e){};" );
    

    solved the issue for me

    0 讨论(0)
  • 2020-11-27 19:08
    def close_all_popups(driver):
        driver.window_handles
        for h in driver.window_handles[1:]:
            driver.switch_to_window(h)
            driver.close()
        driver.switch_to_window(driver.window_handles[0])
    
    0 讨论(0)
提交回复
热议问题