I am trying to wait for a page to fully load with Selenium, and tried to use code from other answers here: https://stackoverflow.com/a/30385843/8165689 3rd method in this answer using Selenium's 'staleness_of' property, and originally at: http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html
However, I think I have some problem with the Python yield
keyword specifically in this code. Based on the above, I have the method:
@contextmanager
def wait_for_page_load(driver, timeout = 30):
old_page = driver.find_element_by_tag_name('html')
yield WebDriverWait(driver, timeout).until(staleness_of(old_page))
This doesn't get called by Python, breakpoint shows it is skipped. I also have same problem with apparent original code:
@contextmanager
def wait_for_page_load(driver, timeout = 30):
old_page = driver.find_element_by_tag_name('html') # up to here with decorator, the function is called OK, with 'yield' it is NOT called
yield
WebDriverWait(driver, timeout).until(staleness_of(old_page))
But if I delete the yield
statement onwards this function does at least get called:
@contextmanager
def wait_for_page_load(driver, timeout = 30):
old_page = driver.find_element_by_tag_name('html')
Anyone know how I should write the yield statement? I'm not experienced with yield, but it looks like Python has to yield
something, so perhaps original code which seems to have yield in line of its own has a problem?