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
  • 788
  • 2
  • 12
  • 30

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
  • 462,703
  • 120
  • 1,088
  • 1,195