How do I scroll down vertically in a specific div in a web page

前端 未结 4 2092
情书的邮戳
情书的邮戳 2021-01-22 18:48

I have searched all the forums but I didn\'t get a correct answer for my issue. My web page to test has a link hidden below, and I am trying to find it manually by searching for

4条回答
  •  遇见更好的自我
    2021-01-22 19:21

    Non-JQuery solution based on this post.

    ((JavascriptExecutor) driver).executeScript(
        "arguments[0].scrollTop=arguments[1].offsetTop",
        divWithScrollbarElement,
        elementToScrollTo);
    

    where divWithScrollbarElement is the div element which you are looking to scroll, and elementToScrollTo is the child element which you want to make viewable (which in my case was actually the parent of the element which I was initially trying to view). If elementToScrollTo is not actually in the DOM yet, you may need to use the script once to scroll down as far as possible, and then again once more elements have loaded.

提交回复
热议问题