0

I am trying to focus on an element to make this element in the center of the screen or way from the top to be above the middle. This is what I did

.FindElementById("toBePaid[" & r - 1 & "]").ExecuteScript "this.scrollIntoView(true); window.scrollBy(0, -(window.innerHeight - this.clientHeight)-150);"

But I couldn't see the element as it is at the top-most of the screen of the website.

I have tried too

.FindElementById("toBePaid[" & r - 1 & "]").ScrollIntoView True

But the same problem is still there.

1 Answer 1

0

With the help of @QHarr I could dolve it

Function ScrollIntoViewCenter(element As WebElement)
  Const JS_SCROLL_CENTER = _
    "this.scrollIntoView(true);" & _
    "var y = (window.innerHeight - this.offsetHeight) / 2;" & _
    "if (y < 1) return;" & _
    "for (var e=this; e; e=e.parentElement) {" & _
    "  if (e.scrollTop == 0) continue;" & _
    "  var yy = Math.min(e.scrollTop, y);" & _
    "  e.scrollTop -= yy;" & _
    "  if ((y -= yy) < 1) return;" & _
    "}" & _
    "window.scrollBy(0, -y);"
  
  element.ExecuteScript JS_SCROLL_CENTER
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.