添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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 9, 2016 at 21:57

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!

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.