Skip to content
Related Articles

Related Articles

Improve Article

Scroll Web Page Base On Pixel Method Using Selenium in Python

  • Last Updated : 04 Jan, 2021

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



Python3




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.

Python3




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.

Python3




driver.maximize_window()

Step 4: Scrolling base on the pixel.

Python3




driver.execute_script("window.scrollBy(0,2000)","")

Below is the full Implementation:

Python3




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 pixcel
driver.execute_script("window.scrollBy(0,2000)","")
time.sleep(4)

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :