'How to scroll to bottom of div using Selenium Python

I am trying to get the names of all the guests attending my event and have selected 'going' on my event.

I go to the event page, click on the X going / Y interested option and a dialog box opens. The dialog box can be scrolled and has to be scrolled to get the list of all the guests of my events. It is a typical scrollable window with lazy loading.

I have tried using execute_script function to scroll down a little but since I don't know enough javascript, I could not modify it to reach the end of the dialog box.

How can I scroll to the end of the dialog box?



Solution 1:[1]

If you know the element id you can use this:

from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).move_to_element(driver.sl.find_element_by_id('my-id')).perform()

Solution 2:[2]

Have tried the below options.Try this with your div_element.

driver.execute_script("return arguments[0].scrollIntoView(true);", div_element)

Solution 3:[3]

I used zooming out for my dynamic content. Elements get small and you get to fetch 'em all.

driver.execute_script("document.body.style.zoom='zoom %'")

Solution 4:[4]

First you have to parse the command line input and for that you have to use process.argv() method.

 const arguments = process.argv.slice(2); // delete first two arguments as the..
 // first one is the process execution path
 //second one is the path for the js file

 console.log(arguments[0]);

Now run "./task help" on the shell you will see the output 'help' Using above you can parse your cli input. After that you can use if else or switch case statements for various inputs and executes them. For e.g.

if(arguments[0] === "help") {
    const help = `Usage :-
    $ ./task add 2 hello world    # Add a new item with priority 2 and text "hello world" to the list
    $ ./task ls                   # Show incomplete priority list items sorted by priority in ascending order
    $ ./task del INDEX            # Delete the incomplete item with the given index
    $ ./task done INDEX           # Mark the incomplete item with the given index as complete
    $ ./task help                 # Show usage
    $ ./task report               # Statistics`;

    console.log(help);
}
// like that you can do for others

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium
Solution 2 KunduK
Solution 3 Andrey S
Solution 4