H
H
Held69912021-08-01 19:49:11
Python
Held6991, 2021-08-01 19:49:11

How to make an element scroll in Selenium?

Hello, how to change this script so that it scrolls not
the page, but the element?
6106d0997ac4e589838689.png
6106d27122ee2878914912.png

def scroll_down():
    """A method for scrolling the page."""

    # Get scroll height.
    last_height = driver.execute_script("return document.body.scrollHeight")

    while True:

        # Scroll down to the bottom.
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

        # Wait to load the page.
        sleep(2)

        # 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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ramis, 2021-08-18
@Held6991

You can try to do this, in the console it works

document.getElementsByClassName("isgrP")[0].scrollBy(0,100)

611c9016a39de072000191.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question