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

前端 未结 4 2033
情书的邮戳
情书的邮戳 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:02

    Check if this works for you.

    var s = $('#ctl00_Menu1_scrollDiv').scrollTop(); 
    

    This will give the current value of the scroll in the div.Use this only if you want to scroll inside a div to a certain point dynamically. Otherwise you can hardcode the scrollTop value inside animate()

    Using the current value of your scroll you can parameterize the given below scrollTop parameter

    $("#ctl00_Menu1_scrollDiv").animate({ scrollTop: "100px" }); // Here 100 px is just an example
    

    I had used this to scroll a large div programmatically in my webdriver framework. Also, this will work if your AUT has jQuery loaded in the browser.

    In Java:

    JavascriptExecutor js;
    js = (JavascriptExecutor) driver;
    js.executeScript("$(\"#ctl00_Menu1_scrollDiv\").animate({ scrollTop: \"100px\" })");
    

提交回复
热议问题