1

I want to write a function that can make selenium wait till any given url is fully rendered. I have found a lot of existing answers using explicit wait which does not work here. I want to have some general function for any urls.

What I have tried is:

def get_html_doc(driver, url):
    wait = WebDriverWait(driver, 30) #  30 is the max wait time
    driver.get(url)
    wait.until(lambda driver: 
               driver.execute_script("return (typeof jQuery === 'undefined' || jQuery.active == 0)" 
                                     " && (typeof window.angular == 'undefined'"
                                     " || angular.element(document).injector() === 'undefined)'"
                                     " && document.readyState === 'complete'"))
    return str(driver.find_element_by_xpath("/html/body").get_attribute("outerHTML"), "lxml")

The idea is that I respectively check the status of jquery, angular and jsp if there is any. However, when using this function for the url the url below, https://stores.sainsburys.co.uk/list/place/@51.5073509,-0.12775829999998223/1/all The html document I get from this function is different from the one in browser.

How do I fix this function?

F.Lavenir
  • 3
  • 3
ikokko
  • 11
  • 2

0 Answers0