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

后端 未结 4 539
北荒
北荒 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条回答
  •  天涯浪人
    2020-12-04 02:56

    To manage any of the errors you can got, you only have to put into a try/block using the Exception NAMEERROR like this:

    from selenium.common.exceptions import UnexpectedAlertBehaviour
    from selenium.common.exceptions import UnexpectedAlertPresentException
    try:
      var = driver.some_function()
      return True
    except UnexpectedAlertBehaviour:
      print "We have raised the UnexpectedAlertBehaviour"
      return False
    except UnexpectedAlertPresentException:
      print "UnexpectedAlertPresentException"
      return False
    

    I know this code is not in Java, but the basis is the same. Try/Catch with name of exception. You can see an example of this on my post of the alerts() handling here

提交回复
热议问题