1

I am currently using the following piece of code to navigate to the middle of the page but it is not working properly.

driver.execute_script("window.scrollTo(0, document.body.scrollHeight/2);")

Also, I am trying to use

element.location_once_scrolled_into_view

Can someone help ?

Gokul
  • 740
  • 2
  • 14
  • 27

1 Answers1

1

You may call .scrollIntoView() in your script passing in your element as an argument:

driver.execute_script("arguments[0].scrollIntoView();", element)

There is also move_to_element() built-in selenium action:

from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).move_to_element(element).perform()

The differences were perfectly highlighted here:

alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148