There are two ways of doing this:
- Using JavaScript and the
scrollIntoView()
function
- Using Actions
Using JavaScript and the scrollIntoView()
function
Java
WebElement element = driver.findElement(By.id("myID"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(500);
Python
element = driver.find_element_by_id("myID")
driver.execute_script("arguments[0].scrollIntoView(true);", element)
time.sleep(0.5)
C#
WebElement element = driver.FindElement(By.Id("myID"));
((IJavascriptExecutor) driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
Thread.Sleep(500);
Using Actions
Java
WebElement element = driver.findElement(By.id("myID"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
Python
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(driver.sl.find_element_by_id("myID")).perform()
C#
WebElement element = driver.FindElement(By.id("myID"));
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Perform();