So basically your requirement is to scroll a particular section of a webpage.
While most of the available answers revolve around scrolling the complete web page itself, it is indeed possible to scroll a particular segment of the webpage entirely.
There are a fair number of sites where the scrollbar is not an identifiable element in source code and therefore clicked to scroll the section down.
What you can do in such a case is to manipulate the section using javascript.
However, if the scrollbar is identified in the source code, configuring a simple click action would get the job done.
Firstly identify the sub-section of the webpage that you want to scroll
xpath_element = "//aside[@class='sidebar mCustomScrollbar_mCS_2']//div[@class='mCSB_container']"
section = driver.find_element(By.XPATH, xpath_element)
Now for an example, let's say you want to scroll the particular section 3 times, therefore we can initialize a counter variable for the same:
counter = 0
while counter < 3: # this will scroll 3 times
driver1.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;',
section)
counter += 1
# add a timer for the data to fully load once you have scrolled the section
time.sleep(5) # You might need to install time library to use this statement
And this will help you scroll the section in your webpage. Please note that you can modify the execute_script() as per your requirement, so for example if you wish to scroll to the bottom of the section in each attempt, you can simply use:
driver.execute_script(
'arguments[0].scrollTop = arguments[0].scrollTop + document.getElementById("search-results-container").scrollHeight;',
section,
)
where you are getting the scrolling height of section that you were trying to scroll.