python selenium - takes a lot of time when it does not find elements python selenium - takes a lot of time when it does not find elements selenium selenium

python selenium - takes a lot of time when it does not find elements


Try to use ExplicitWait as below:

from selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait as waitfrom selenium.common.exceptions import TimeoutExceptiontry:    Lines = wait(driver, 1).until(EC.presence_of_all_elements_located((By.XPATH, '//*[@id="top"]/div[contains(@style, "display: block;")]/'                'div[contains(@style, "display: block;")]//tbody//a[contains(@title, "Line")]')))except TimeoutException:    pass

This should allow you to wait for 1 second until at least one element found and get the list of required WebElements or do nothing otherwise