3
driver.get(
    "http://www.uitestingplayground.com/scrollbars")
time.sleep(10)
driver.execute_script(
    "arguments[0].scrollIntoView()", driver.find_element_by_id("hidingButton"))

I am trying to scroll the hode button into center of the element but the vertical scroll bar is not properly at center.

Is there any way to scroll it to the center ?

1 Answer 1

2
driver.get(
    "http://www.uitestingplayground.com/scrollbars")
time.sleep(10)
driver.execute_script(
    "arguments[0].scrollIntoView({'block':'center','inline':'center'})", driver.find_element_by_id("hidingButton"))

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

use inline and block options

1
  • 1
    it worked :) thank you
    – sdPeter
    Apr 8, 2021 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.