我想检查我正在测试的页面中是否有一个元素,但是我不希望find_element_by_xpath函数在不存在的情况下抛出一个NoSuchElement异常。(If the first find_element fails I want this code)
这在本质上是一个if else语句,所以我更喜欢使用if else语句,这样我就可以在这些代码块中找到不同的无此类元素异常如果元素</e
我很好奇python中是否有一种方法可以在try/catch块中继续运行,在捕获异常之后,查看它的属性,如果不相关,则继续在堆栈中运行。try:except AppleError as apple_ex:
# look at 'apple_ex.error_code' error body, and if# In other words, proceed to except BananaEr