Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python.
A Scrollbar is helped you to circulate round display in vertical route if the modern-day web page scroll does now no longer the seen place of the display. It is used to transport the window up and down. Selenium Webdriver does now no longer requires scroll to carry out moves because it manipulates DOM. But in positive internet pages, factors best emerge as seen as soon as the person has scrolled to them. In such instances, scrolling can be necessary.
Requirements:
- selenium
- You need to install chromedriver and set the path. Click here to download.
Step-by-step Approach:
Step 1: Import required modules
from selenium import webdriver
import time
from webdriver_manager.chrome import ChromeDriverManager
# create instance of Chrome webdriver driver = webdriver.Chrome(ChromeDriverManager().install())
|
Step 2: Taking any URL.
from selenium import webdriver
import time
from webdriver_manager.chrome import ChromeDriverManager
# create instance of Chrome webdriver driver = webdriver.Chrome(ChromeDriverManager().install())
#url |
Step 3: Maximize the window.
driver.maximize_window() |
Step 4: Scrolling base on the pixel.
driver.execute_script( "window.scrollBy(0,2000)" ,"")
|
Below is the full Implementation:
from selenium import webdriver
import time
from webdriver_manager.chrome import ChromeDriverManager
# create instance of Chrome webdriver driver = webdriver.Chrome(ChromeDriverManager().install())
#url #maximize window driver.maximize_window() #scroll by pixel driver.execute_script( "window.scrollBy(0,2000)" ,"")
time.sleep( 4 )
|
Output: