How to wait until page auto scroll completed

3.8k views Asked by At

Regarding this issue, I want to know if there is a way to wait until page auto scroll completed?

The problem is that when you click on the "Next" ("Volgende") button on pagination (URL is https://www.iens.nl/restaurant+utrecht) for the first time webdriver redirects you to the next page and automatically scroll up to the top of page. So if to execute

WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Volgende'))) again, just after redirection, webdriver will find button, but click on some other element as focus moves up for about a second.

For now only solution to keep clicking "Next" button until last page reached is to use time.sleep:

while True:
    try:
        click_icon = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Volgende')))
        click_icon.click()
        time.sleep(2)  # to wait until page scrolled
    except:
        break

but it's obviously not the best idea...

P.S. Also I wonder if there is a possibility to disable page auto scroll feature. Switching general.autoScroll to False in Firefox about:config doesn't make any effect

1

There are 1 answers

1
Guy On BEST ANSWER

The html contains element with tag <main> that receives attribute style when the page is not scrolled all the way up. I suggest you wait until the tag doesn't have this attribute

WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'main:not([style*="margin-top"])')))