Selenium WebDriver how to close browser popup

前端 未结 9 1109
悲&欢浪女
悲&欢浪女 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 18:48

    You might try using keyboard events. So once the window pops up:

    Tab onto the "Ok" button.

    driver.Keyboard.PressKey(Keys.Tab);
    

    You'll have to play around to see how many tab presses are required.

    Then hit space.

    driver.Keyboard.PressKey(Keys.Space);
    

    Yeah it's sort of a hack, but WebDriver is still pretty immature.

    EDIT: This will work for "real" popups, but as another answerer said, maybe not for weird in-page things. Basically, if you can tab to the close button manually, this method should work.

提交回复
热议问题