Selenium 捕捉selenium的异常

捕捉selenium异常需要先导入异常

from selenium.common.exceptions import TimeoutException

try:
    cur_comment_items = WebDriverWait(driver, 10).until(
        EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.weiboitem.active span.heightbox"))
    )
except TimeoutException :
    break

你可能感兴趣的:(Selenium 捕捉selenium的异常)