0

I have a python script that is utilizing selenium with the chrome webdriver. When I load pages sometimes it'll get stuck because some javascript is trying to load. If I run the line:

driver.execute_script("$(window.stop())")

that occasionally (but not reliably) works to simulate the stop browser action. My other thought was to change the page_load_timeout to 5s. That will throw an error when this annoying javascript isn't loading. I want to stop the page from loading with the timeout, but then run the function that I initially wanted to run... How do I accomplish that?

1 Answer 1

1

One way is, you have to assert by inspection which element could do the delay and with the element's #id you you can wait for that element to load with a time out.

try:
    WebDriverWait(driver, 60).until((EC.visibility_of_element_located(By.Id, 'id')))

except TimeoutException:
    pass

Or you can use the staleness_of approach, explained in related SO answers,

    @contextlib.contextmanager
    def wait_for_page_load(self, timeout=30):
        old_page = self.find_element_by_tag_name('html')
        yield
        WebDriverWait(self, timeout).until(staleness_of(old_page))
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not waiting for an element to appear, the elements are already on the page, but the page is waiting to load some javascript before I can do actions on the elements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.