To scroll down a page, use the driver.execute_script() method to locate the particular position by providing the parameters.
The code below can be used by teams to scroll down in Selenium
#import “webdriver”
import selenium webdriver
#load chrome drivers from the path where drivers are installed
driver = webdriver.Chrome(executable_path='Path of exe driver\chromedriver.exe')
#maximize the browser
driver.maximize_window()
#navigate to the url
driver.get(“https://www.worldometers.info/geography/flags-of-the-world/”)
#Scroll down page by Pixel
driver.execute_script(“window.scrollBy(0,9000)”, “”)
#Scroll page till element is visible
countryFlag = driver.find_element_by_xpath(“xpath of the element”)
driver.execute_script(“arguments[0].scrollIntoView();”, countryFlag)
#Scroll till end of the page
driver.execute_script(“window.scrollBy(0, document.body.scrollHeight)”)
import selenium webdriver
#load chrome drivers from the path where drivers are installed
driver = webdriver.Chrome(executable_path='Path of exe driver\chromedriver.exe')
#maximize the browser
driver.maximize_window()
#navigate to the url
driver.get(“https://www.worldometers.info/geography/flags-of-the-world/”)
#Scroll down page by Pixel
driver.execute_script(“window.scrollBy(0,9000)”, “”)
#Scroll page till element is visible
countryFlag = driver.find_element_by_xpath(“xpath of the element”)
driver.execute_script(“arguments[0].scrollIntoView();”, countryFlag)
#Scroll till end of the page
driver.execute_script(“window.scrollBy(0, document.body.scrollHeight)”)
Post a Comment