How can I get endless expectations?

Viewed 64

I use Selenium and I need to endlessly wait for the page to load (because it takes a couple of hours to load) and then parse data from it. How can I do this?

I use some code like this:

wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "modal-title")))
1 Answers

You can use WebDriverWait() to achieve that. For example, the following code waits for five hours or until it finds the element.

hours_to_wait = 5

element = WebDriverWait(driver, hours_to_wait *60*60).until(
EC.visibility_of_all_elements_located((By.XPATH, 'hereIsYourXpath')))

Or:

element = WebDriverWait(driver, hours_to_wait *60*60).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )

Or in your case:

element = WebDriverWait(driver, hours_to_wait *60*60).until(
        EC.presence_of_element_located((By.CLASS_NAME, "modal-title"))
    )

You need to import these:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Related