Scrolling to top of the page in Python using Selenium

后端 未结 6 1448
悲哀的现实
悲哀的现实 2020-11-27 07:30

I\'m having issues with scrolling to the top of the web page when using Python and Selenium.

When the page loads for some reason you are taken to the bottom of the

6条回答
  •  天命终不由人
    2020-11-27 07:58

    You can consider to locate the element in the HTML DOM first, then we can scroll the element into the Viewport as follows:

    element = driver.find_element_by_xpath("element_xpath")
    self.driver.execute_script("return arguments[0].scrollIntoView(true);", element)
    

提交回复
热议问题