0

I am using python selenium to scroll a webpage, i am trying to get to the bottom of the page by clicking on the scroll element but it's returning this error: MoveTargetOutOfBoundsException: move target out of bounds

My code so far:

from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
scrollbar_needed = driver.find_element_by_xpath("//div[@class='antiscroll-scrollbar antiscroll-scrollbar-vertical antiscroll-scrollbar-shown']")
actions.click_and_hold(scrollbar_needed).move_by_offset(0,5000).release().perform()

Is there another way to scroll using the path of "scrollbar_needed"?

2 Answers 2

1

There are couple of ways of scrolling through a dynamic webpage.

option 1: If you want to scroll a specific limit you can use this

driver.execute_script("window.scrollTo(0, 1000);")
      

option 2: If you want to scroll and reach to end of the page you can use this

driver.find_element(By.TAG_NAME,'body').send_keys(Keys.END)
      

option 3: If it is lazy loading page you can use that option as well.

     # Get scroll height
      last_height = driver.execute_script("return document.body.scrollHeight")
      limit=500
      while True:
         # Scroll down to to a limit
         driver.execute_script("window.scrollTo(0," + limit + ");")

         # Wait to load page
         time.sleep(1)
         # increase the scroll height
         limit=limit+500
         # Calculate new scroll height and compare with last scroll height
         new_height = driver.execute_script("return document.body.scrollHeight")
         if new_height == last_height:
             break
         last_height = new_height  
Sign up to request clarification or add additional context in comments.

Comments

0

Here it is:

driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")

1 Comment

Code-only answers are not that useful. Spend a minute to add some explanation of what the code does and why it would answer the question/be helpful to solve the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.