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?

5
  • have you tried clicking on the div and then send keys page down or control End? Commented Mar 10, 2020 at 15:17
  • @supputuri a random div is not clickable, is it? Commented Mar 10, 2020 at 15:18
  • what do you mean by random div, does it have dynamic attribute values? Commented Mar 10, 2020 at 15:36
  • Refer to the link: stackoverflow.com/questions/59838948/… Commented Mar 11, 2020 at 10:20
  • @supputuri page down or control end does nothing on that div. In "normal mode" it is only scrollable by the mouse Commented Mar 12, 2020 at 13:35

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

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.