How to handle the “unexpected alert open”?

后端 未结 7 514
耶瑟儿~
耶瑟儿~ 2020-12-28 18:07

I got an issue with Selenium throwing timeout exception because of a pop up window

  unexpected alert open
  not provide any stacktrace inform         


        
相关标签:
7条回答
  • 2020-12-28 18:41

    Methods to handle alerts in Selenium

    1. Decide on each individually

    If you need to take action on each alert in your tests individually, the driver gives you the option to switch to the alert and decide to either accept or dismiss it.

    driver.switchTo().alert().accept();
    

    1. Handle by default setup

    When you want all the alerts handled in the same way, you can set a global capability at the start of the test execution to ACCEPT, INGORE or DISMISS alerts by default when they appear.

    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    

    1. Using Robot class

    Alternatively, you could use Robot class to send an Enter key event, which would accept the alert.

    Robot r = new Robot();
     
    r.keyPress(KeyEvent.VK_ENTER);
    r.keyRelease(KeyEvent.VK_ENTER);
    

    0 讨论(0)
提交回复
热议问题