0

I am using Java and Selenium to write a test. the target application has some inner pages, and I need to scroll to top of a web element in one the pages. I used:

jse.executeScript("arguments[0].scrollTop", element);

but it did not work, I also used scrollIntoView but it did not work as the element is covered by another element.

LoveJavaTwo
  • 215
  • 3
  • 17
  • 1
    You may want to add the mark-up for the page to your question. As it stands now, there isn't enough information to provide an answer. – Brian Feb 09 '16 at 21:57
  • I used `scrollIntoView(false)` and it worked – LoveJavaTwo Feb 09 '16 at 22:23
  • The answer to this question: http://stackoverflow.com/questions/35355643/selenium-webdriver-element-not-clickable-error-in-firefox/35359067#35359067 should help you. – Ardesco Feb 12 '16 at 10:00

1 Answers1

0

Update Just saw your comment, glad you got it working in a more succinct way.


Make the element in the foreground invisible, then use scrollIntoView().

...Something like jse.executeScript('arguments[0].style.visibility="hidden"', element)?

My Python solution, it should translate easily:

def makeInvisible(driver, element):
    driver.execute_script('arguments[0].style.visibility="hidden"', element)

I usually get the element by xpath and then pass it to that function. You can also double-check if something is hidden with an equivalent for:

def isInvisible(driver, element):
    return driver.execute_script('return window.getComputedStyle(arguments[0]).display === \'none\'', element)

And of course write a function to make an element visible again with the above. Hope that helps!

bryanb
  • 39
  • 7