How to scroll to a webpage element with Selenium?

How to scroll to a webpage element with Selenium?

QA 0

Selenium provides the ‘move_to_element’ method that will scroll to the element in the DOM, and place the mouse on the element, which subsequently makes it easy to click:

Python Code:

import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

# navigate to Instagram
driver = webdriver.Firefox()
driver.get('https://www.instagram.com')
# sleep 1 second
x.Wait(1000)

element = driver.find_element_by_id("myID")
actionchains = ActionChains(driver)
actionchains.move_to_element(element).perform()