selenium scroll python usign element code example
Example 1: how to scroll by in selenium python
for i in range(20):
driver.execute_script("window.scrollBy(0, 250)")
time.sleep(1)
Example 2: selenium scroll to element python
element = driver.find_element_by_id("my-id")
desired_y = (element.size['height'] / 2) + element.location['y']
current_y = (driver.execute_script('return window.innerHeight') / 2) + driver.execute_script('return window.pageYOffset')
scroll_y_by = desired_y - current_y
driver.execute_script("window.scrollBy(0, arguments[0]);", scroll_y_by)