Tracking with JavaScript if Ajax request is going on in a webpage or Intercept XMLHttpRequest through Selenium Web driver

后端 未结 3 401
灰色年华
灰色年华 2021-02-01 20:32

I am using Selenium WebDriver for crawling a web site(only for example, I will be crawling other web sites too!) which has infinite scroll.

Problem statement:

3条回答
  •  无人及你
    2021-02-01 21:14

    We had to solve the same problem, and managed using a long Javascript function. Just need to add checks to see which library is not undefined.

    PS Thanks for giving me an easy answer for how to check for in progress Prototype requests!

    eg. Handle JQuery and XHR/Prototype

    var jsExecutor = /*Get your WebDriverInstance*/ as IJavaScriptExecutor;
    while(/*your required timeout here*/)
    {
        var ajaxComplete = 
          jsExecutor.ExecuteScript("return ((typeof Ajax === 'undefined') ||   
          Ajax.activeRequestCount == 0) && ((typeof jQuery === 'undefined') || $.active == 0)");
        if (ajaxIsComplete)
          return
    }
    

提交回复
热议问题