<tfoot id='HKCB1'></tfoot>

      <legend id='HKCB1'><style id='HKCB1'><dir id='HKCB1'><q id='HKCB1'></q></dir></style></legend>

        <bdo id='HKCB1'></bdo><ul id='HKCB1'></ul>
      1. <small id='HKCB1'></small><noframes id='HKCB1'>

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

        Selenium - 完整的ajax加载自动滚动到页面底部

        时间:2023-05-28
          <i id='BIwCT'><tr id='BIwCT'><dt id='BIwCT'><q id='BIwCT'><span id='BIwCT'><b id='BIwCT'><form id='BIwCT'><ins id='BIwCT'></ins><ul id='BIwCT'></ul><sub id='BIwCT'></sub></form><legend id='BIwCT'></legend><bdo id='BIwCT'><pre id='BIwCT'><center id='BIwCT'></center></pre></bdo></b><th id='BIwCT'></th></span></q></dt></tr></i><div id='BIwCT'><tfoot id='BIwCT'></tfoot><dl id='BIwCT'><fieldset id='BIwCT'></fieldset></dl></div>

              <bdo id='BIwCT'></bdo><ul id='BIwCT'></ul>
            • <small id='BIwCT'></small><noframes id='BIwCT'>

              • <legend id='BIwCT'><style id='BIwCT'><dir id='BIwCT'><q id='BIwCT'></q></dir></style></legend>
              • <tfoot id='BIwCT'></tfoot>

                  <tbody id='BIwCT'></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加载自动滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文章

                1. <legend id='mW9J0'><style id='mW9J0'><dir id='mW9J0'><q id='mW9J0'></q></dir></style></legend>
                  1. <small id='mW9J0'></small><noframes id='mW9J0'>

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

                        <bdo id='mW9J0'></bdo><ul id='mW9J0'></ul>