Search code examples
pythonseleniumscrollweb-crawlerinfinite-scroll

Scrolling task of Selenium is not worked for me in Python environment


I want to write a script with adjustable speed. I want to scroll the page into a specific height of the page. I used window.scrollTo as follows:

driver.execute_script("window.scrollTo(0, 10)")

Although there is no error, after running, we cannot see any change in scroll position. Could you help me, please?


Solution

  • The problem was solved for me by the code as follows:

    src = driver.find_element_by_xpath("/html/body/div/div/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[2]/div")
    
    driver.execute_script("arguments[0].scrollTop = (0,10)", src)