python selenium webscraping “NoSuchElementException” not recognized

后端 未结 2 1888
一生所求
一生所求 2020-12-29 00:45

Sometimes on a page I\'ll be looking for an element which may or may not be there. I wanted to try/catch this case with a NoSuchElementException, which selenium

相关标签:
2条回答
  • 2020-12-29 01:26

    You sould use from selenium.common.exceptions import * and then write except NoSuchElementException

    0 讨论(0)
  • 2020-12-29 01:41

    You need to import the exception first

    from selenium.common.exceptions import NoSuchElementException
    

    and then you can reference it

    except NoSuchElementException:
        # handle the element not existing
    
    0 讨论(0)
提交回复
热议问题