Scrolling to top of the page in Python using Selenium
You can simply use CTRL
+ HOME
keys. It will scroll to the top of the page.
from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
You can consider to locate the element in the HTML DOM
first, then we can scroll
the element into the Viewport
as follows:
element = driver.find_element_by_xpath("element_xpath")
self.driver.execute_script("return arguments[0].scrollIntoView(true);", element)