Skip to content Skip to sidebar Skip to footer

Selenium Python Unable To Scroll Down

Trying to scroll down to the bottom of the page with selenium-webdriver python so that more products load. driver = webdriver.Firefox() driver.get('https://www.woolworths.com.au/S

Solution 1:

You can try these move_up and move_down function:

driver.maximize_window()
driver.get('https://www.woolworths.com.au/Shop/Browse/back-to-school/free-school-labels')
driver.implicitly_wait(15)
centerPanel = driver.find_element_by_css_selector("#center-panel > div[class*='hideScroll-wrapper']")
jsScript = """
        function move_up(element) {
            element.scrollTop = element.scrollTop - 1000;
        }

        function move_down(element) {
            element.scrollTop = element.scrollTop + 1000;
        }

        move_down(arguments[0]);
        move_down(arguments[0]);
        """
driver.execute_script(jsScript, centerPanel)

time.sleep(3) 

jsScript = """
        function move_up(element) {
            element.scrollTop = element.scrollTop - 1000;
        }

        function move_down(element) {
            console.log('Position before: ' + element.scrollTop);
            element.scrollTop = element.scrollTop + 1000;
            console.log('Position after: ' + element.scrollTop);
        }

        move_up(arguments[0]);
        """
driver.execute_script(jsScript, centerPanel)

Solution 2:

You can try using Action Chains

element = driver.find_element_by_id("id") # the element you want to scroll to 
ActionChains(driver).move_to_element(element).perform()

Solution 3:

I just tried with this approach and it worked for me:

element = driver.find_element_by_xpath("//div[@class='center-content']")
driver.execute_script("return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", element)

First you select the div element of the page which you want to scroll down, and then you scroll down within that element.

OBS: I added an offset when defining the scrollHeight because if you scroll to the absolute bottom it doesn't load more objects. It starts loading the catalog when you move closer to the bottom without reach it.

document.documentElement.scrollHeight-10

Post a Comment for "Selenium Python Unable To Scroll Down"