0

I am wondering how to scroll on a scrollable element in a web page. I found plenty of answers about how to scroll the whole page (working well) but here it's an inner specific div that is scrollable that I want to scroll to the bottom.

How can I do that with selenium for python?

Laetis
  • 1,337
  • 3
  • 16
  • 28

1 Answers1

0

I ran into a similar issue and solved it like this:

If this is your HTML:

<ul class="list">
    <li class="list__element">1</li>
    <li class="list__element">2</li>
    <li class="list__element">3</li>
    <li class="list__element">4</li>
    <li class="list__element">5</li>
    <li class="list__element">6</li>
    <li class="list__element">7</li>
</ul>

Select all the child elements of your list like so:

list_elements = driver.find_elements(By.CLASS_NAME, 'list__element')

After that, you can loop over that list and scroll to a specific item. Note: If your list progressively loads new list elements you need to accoaunt for that.

for comment in comments:
        ActionChains(driver)\
        .scroll_to_element(comment)\
        .perform()
        time.sleep(.1)