<small id='6Ro92'></small><noframes id='6Ro92'>

      1. <i id='6Ro92'><tr id='6Ro92'><dt id='6Ro92'><q id='6Ro92'><span id='6Ro92'><b id='6Ro92'><form id='6Ro92'><ins id='6Ro92'></ins><ul id='6Ro92'></ul><sub id='6Ro92'></sub></form><legend id='6Ro92'></legend><bdo id='6Ro92'><pre id='6Ro92'><center id='6Ro92'></center></pre></bdo></b><th id='6Ro92'></th></span></q></dt></tr></i><div id='6Ro92'><tfoot id='6Ro92'></tfoot><dl id='6Ro92'><fieldset id='6Ro92'></fieldset></dl></div>
        <tfoot id='6Ro92'></tfoot>
        <legend id='6Ro92'><style id='6Ro92'><dir id='6Ro92'><q id='6Ro92'></q></dir></style></legend>
          <bdo id='6Ro92'></bdo><ul id='6Ro92'></ul>
      2. Selenium - 完整的ajax加载自动滚动到页面底部

        时间:2023-10-01

        • <i id='g1DyL'><tr id='g1DyL'><dt id='g1DyL'><q id='g1DyL'><span id='g1DyL'><b id='g1DyL'><form id='g1DyL'><ins id='g1DyL'></ins><ul id='g1DyL'></ul><sub id='g1DyL'></sub></form><legend id='g1DyL'></legend><bdo id='g1DyL'><pre id='g1DyL'><center id='g1DyL'></center></pre></bdo></b><th id='g1DyL'></th></span></q></dt></tr></i><div id='g1DyL'><tfoot id='g1DyL'></tfoot><dl id='g1DyL'><fieldset id='g1DyL'></fieldset></dl></div>
        • <legend id='g1DyL'><style id='g1DyL'><dir id='g1DyL'><q id='g1DyL'></q></dir></style></legend>
          <tfoot id='g1DyL'></tfoot>

        • <small id='g1DyL'></small><noframes id='g1DyL'>

                <bdo id='g1DyL'></bdo><ul id='g1DyL'></ul>
                  <tbody id='g1DyL'></tbody>

                  本文介绍了Selenium - 完整的ajax加载自动滚动到页面底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个网页,当您滚动到底部时,它会通过 ajax 加载更多结果.您可以在它完成之前对其进行多次迭代.有点像 facebook 的做法.

                  I have a webpage where when you scroll to the bottom it then loads more results via ajax. You can do several iterations of this before it completes. Bit like what facebook does.

                  我正在尝试编写一个 selenium 脚本以一直到页面末尾,直到它完成.

                  I am trying to write a selenium script to keep going to the end of the page until it completes.

                  类似这样的一半完成它..我只是不知道如何确定页面是否在底部 - 所以我可以将它放在某种循环中?

                  Something like this sort of half completes it.. I just don't know how to determine if page is at the bottom - so i can put it inside a loop of some sort?

                  我的尝试

                      By selBy = By.tagName("body");
                  
                      driver.findElement(selBy).sendKeys(Keys.PAGE_DOWN);
                      System.out.println("Sleeping... wleepy");
                  
                      Thread.sleep(5000);
                      driver.findElement(selBy).sendKeys(Keys.PAGE_DOWN);
                  
                      System.out.println("Sleeping... wleepy1");
                      Thread.sleep(3000);
                  
                      //etc...
                  

                  会像这样吗?
                  hasScroll() 不是真正的方法.我把它放在那里是为了展示我想要实现的目标

                  Could Look like this?
                  hasScroll() isnt a real method. I put that there to demonstrate what im trying to achieve

                     while (driver.findElement(By.tagName("body")).hasScroll()) {
                          driver.findElement(selBy).sendKeys(Keys.PAGE_DOWN);
                          System.out.println("Sleeping... wleepy");
                          Thread.sleep(2000);
                     }
                  

                  推荐答案

                  试试这个方法:

                  //Get total height
                  By selBy = By.tagName("body"); 
                  int initialHeight = driver.findElement(selBy).getSize().getHeight();
                  int currentHeight = 0;
                  
                  while(initialHeight != currentHeight){
                          initialHeight = driver.findElement(selBy).getSize().getHeight();
                  
                          //Scroll to bottom
                          ((JavascriptExecutor) driver).executeScript("scroll(0," + initialHeight + ");");
                  
                          System.out.println("Sleeping... wleepy");
                          Thread.sleep(2000);
                  
                          currentHeight = driver.findElement(selBy).getSize().getHeight();
                  }
                  

                  希望有帮助!

                  这篇关于Selenium - 完整的ajax加载自动滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 TestNG 报告中包含 Log4j2 消息 下一篇:WebDriver 不能可靠地单击链接或按钮

                  相关文章

                  最新文章

                  <small id='jzyEy'></small><noframes id='jzyEy'>

                  <tfoot id='jzyEy'></tfoot>

                  <i id='jzyEy'><tr id='jzyEy'><dt id='jzyEy'><q id='jzyEy'><span id='jzyEy'><b id='jzyEy'><form id='jzyEy'><ins id='jzyEy'></ins><ul id='jzyEy'></ul><sub id='jzyEy'></sub></form><legend id='jzyEy'></legend><bdo id='jzyEy'><pre id='jzyEy'><center id='jzyEy'></center></pre></bdo></b><th id='jzyEy'></th></span></q></dt></tr></i><div id='jzyEy'><tfoot id='jzyEy'></tfoot><dl id='jzyEy'><fieldset id='jzyEy'></fieldset></dl></div>

                    <bdo id='jzyEy'></bdo><ul id='jzyEy'></ul>
                  <legend id='jzyEy'><style id='jzyEy'><dir id='jzyEy'><q id='jzyEy'></q></dir></style></legend>