- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it possible to scroll down in a webpage using Selenium Webdriver programmed on Python?
Yes it is possible to scroll down in a webpage using Selenium webdriver in Python by using the JavaScript Executor. Selenium can execute JavaScript commands with the help of execute_script method.
The JavaScript command to be used is passed as a parameter to this method. Also, it must be noted that scrolling actions cannot be performed directly with any methods in Selenium.
To scroll down in a page to the end, we have to pass the command window.scrollTo as a parameter to the execute_script method. Also, the values 0 and document.body.scrollHeight are passed as parameters to the window.scrollTo command.
Syntax
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Let us scroll to the page end and obtain the text CONTACT US −
Example
from selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #scroll to page end with JavaScript Executor driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") #identify element at page end m = driver.find_element_by_xpath("//h3[text()='Contact Us']") #get element text s = m.text print("Text is: ") print(s) #close browser driver.quit()
Output
- Related Articles
- How to scroll down a webpage in selenium using Java?
- How to scroll down using Selenium WebDriver with Java?
- How to refresh a webpage using Python Selenium Webdriver?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to scroll the Page up or down in Selenium WebDriver using java?
- How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?
- How can I scroll a web page using selenium webdriver in python?
- How can I verify Error Message on a webpage using Selenium Webdriver?
- How to scroll down the page till page end in the Selenium WebDriver?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to scroll to element with Selenium WebDriver using C#?
- How to scroll up/down a page using Actions class in Selenium?
- How to click on a link using Selenium webdriver in Python.
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- How to click on image in selenium webdriver Python?

Advertisements