How to handle an Alert with “UnexpectedAlertBehaviour” capability in Selenium?

后端 未结 4 537
北荒
北荒 2020-12-04 02:37

In selenium framework 2.25, I see that we have the UnexpectedAlertBehaviour enum type, but I don\'t know how to use it.

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 03:02

    It is a CapabilityType, so you have to express it in the DesiredCapabilities that you pass when creating the driver. In Python I added this behavior to my FireFox drivers using this code:

            selenium.webdriver.DesiredCapabilities.FIREFOX["unexpectedAlertBehaviour"] = "accept"
    

    I haven't tested this Java but in theory it should work:

    DesiredCapabilities cap = new DesiredCapabailities();
    cap.setPreference(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, 
       org.openqa.selenium.UnexpectedAlertBehaviour.ACCEPT);
    WebDriver driver = new FirefoxDriver(cap);
    

提交回复
热议问题