Do we have any generic funtion to check if page has completely loaded in SeleniumUsing selenium wait until to wait some query finished in pythonHow to assert whether page is displayedWait for javascript to execute in selenium-webdriver“Implicitly” waiting for elements to load before assertions fail in WebDriver in PythonReduce Browser load time with Selenium WebdriverHow to avoid script failures because of page elements high loading time in angular application automation?Render crawled HTML in most efficient wayhow to wait for ajax call in selenium webdriver in safari browserPage load strategy for Chrome driver (Updated till Selenium v3.12.0)Don't wait for a page to load using Selenium in PythonJavaScript that executes after page loadSelenium 2: Interrupt a page loadSelenium WebDriver: Wait for complex page with JavaScript to loadWaiting of selenium webdriver until loading completedHow to wait for page load to complete in Chrome browserSelenium webdriver. Endless page loadinghow to check page load if i have more than 50 pagesWhich wait will be used until page loadsdocument.readyState returns 'complete' even when the page is still visibly loadingHow to make selenium 3.4.0 wait for page load?

Copy line and insert it in a new position with sed or awk

Selecting a secure PIN for building access

If Earth is tilted, why is Polaris always above the same spot?

How did Captain America use this power?

Applying a function to a nested list

Write to EXCEL from SQL DB using VBA script

Can PCs use nonmagical armor and weapons looted from monsters?

CRT Oscilloscope - part of the plot is missing

Accidentally deleted the "/usr/share" folder

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

What is the limiting factor for a CAN bus to exceed 1Mbps bandwidth?

Is lying to get "gardening leave" fraud?

How to assert on pagereference where the endpoint of pagereference is predefined

Junior developer struggles: how to communicate with management?

When and why did journal article titles become descriptive, rather than creatively allusive?

Pigeonhole Principle Problem

Why is Arya visibly scared in the library in S8E3?

If Melisandre foresaw another character closing blue eyes, why did she follow Stannis?

Is balancing necessary on a full-wheel change?

How do you center multiple equations that have multiple steps?

How to implement float hashing with approximate equality

Why is Thanos so tough at the beginning of "Avengers: Endgame"?

Is it always OK to ask for a copy of the lecturer's slides?

How does NAND gate work? (Very basic question)



Do we have any generic funtion to check if page has completely loaded in Selenium


Using selenium wait until to wait some query finished in pythonHow to assert whether page is displayedWait for javascript to execute in selenium-webdriver“Implicitly” waiting for elements to load before assertions fail in WebDriver in PythonReduce Browser load time with Selenium WebdriverHow to avoid script failures because of page elements high loading time in angular application automation?Render crawled HTML in most efficient wayhow to wait for ajax call in selenium webdriver in safari browserPage load strategy for Chrome driver (Updated till Selenium v3.12.0)Don't wait for a page to load using Selenium in PythonJavaScript that executes after page loadSelenium 2: Interrupt a page loadSelenium WebDriver: Wait for complex page with JavaScript to loadWaiting of selenium webdriver until loading completedHow to wait for page load to complete in Chrome browserSelenium webdriver. Endless page loadinghow to check page load if i have more than 50 pagesWhich wait will be used until page loadsdocument.readyState returns 'complete' even when the page is still visibly loadingHow to make selenium 3.4.0 wait for page load?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I am trying to check if web page is loaded completed or not (i.e. checking that all the control is loaded) in selenium.



I tried below code:



new WebDriverWait(firefoxDriver, pageLoadTimeout).until(
webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


but even if page is loading above code does not wait.



I know that I can check for particular element to check if its visible/clickable etc but I am looking for some generic solution










share|improve this question
























  • You can check the page of URL to see whether page is loaded or not?

    – Sneha Shinde
    May 14 '18 at 9:58

















2















I am trying to check if web page is loaded completed or not (i.e. checking that all the control is loaded) in selenium.



I tried below code:



new WebDriverWait(firefoxDriver, pageLoadTimeout).until(
webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


but even if page is loading above code does not wait.



I know that I can check for particular element to check if its visible/clickable etc but I am looking for some generic solution










share|improve this question
























  • You can check the page of URL to see whether page is loaded or not?

    – Sneha Shinde
    May 14 '18 at 9:58













2












2








2


3






I am trying to check if web page is loaded completed or not (i.e. checking that all the control is loaded) in selenium.



I tried below code:



new WebDriverWait(firefoxDriver, pageLoadTimeout).until(
webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


but even if page is loading above code does not wait.



I know that I can check for particular element to check if its visible/clickable etc but I am looking for some generic solution










share|improve this question
















I am trying to check if web page is loaded completed or not (i.e. checking that all the control is loaded) in selenium.



I tried below code:



new WebDriverWait(firefoxDriver, pageLoadTimeout).until(
webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


but even if page is loading above code does not wait.



I know that I can check for particular element to check if its visible/clickable etc but I am looking for some generic solution







java selenium selenium-webdriver pageload dom-events






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 18 '18 at 16:36









DebanjanB

48.6k144993




48.6k144993










asked May 14 '18 at 9:31









Ankit SinghAnkit Singh

173




173












  • You can check the page of URL to see whether page is loaded or not?

    – Sneha Shinde
    May 14 '18 at 9:58

















  • You can check the page of URL to see whether page is loaded or not?

    – Sneha Shinde
    May 14 '18 at 9:58
















You can check the page of URL to see whether page is loaded or not?

– Sneha Shinde
May 14 '18 at 9:58





You can check the page of URL to see whether page is loaded or not?

– Sneha Shinde
May 14 '18 at 9:58












5 Answers
5






active

oldest

votes


















3














As you mentioned if there is any generic funtion to check if page has completely loaded in Selenium the answer is No.



First let us have a look at your code trial which is as follows :



new WebDriverWait(firefoxDriver, pageLoadTimeout).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


The parameter pageLoadTimeout in the above line of code doesn't really reseambles to actual pageLoadTimeout().



Here you can find a detailed discussion of pageLoadTimeout in Selenium not working




Now as your usecase relates to page being completely loaded you can use the pageLoadStrategy() set to normal [ the supported values being none, eager or normal ] using either through an instance of DesiredCapabilities Class or ChromeOptions Class as follows :




  • Using DesiredCapabilities Class :



     import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.remote.DesiredCapabilities;

    public class myDemo

    public static void main(String[] args) throws Exception

    System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
    DesiredCapabilities dcap = new DesiredCapabilities();
    dcap.setCapability("pageLoadStrategy", "normal");
    FirefoxOptions opt = new FirefoxOptions();
    opt.merge(dcap);
    WebDriver driver = new FirefoxDriver(opt);
    driver.get("https://www.google.com/");
    System.out.println(driver.getTitle());
    driver.quit();





  • Using ChromeOptions Class :



    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.PageLoadStrategy;

    public class myDemo

    public static void main(String[] args) throws Exception

    System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
    FirefoxOptions opt = new FirefoxOptions();
    opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    WebDriver driver = new FirefoxDriver(opt);
    driver.get("https://www.google.com/");
    System.out.println(driver.getTitle());
    driver.quit();




You can find a detailed discussion in Page load strategy for Chrome driver (Updated till Selenium v3.12.0)




Now setting PageLoadStrategy to NORMAL and your code trial both ensures that the Browser Client have (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.



You can find a detailed discussion in Selenium IE WebDriver only works while debugging



But the Browser Client attaining 'document.readyState' equal to "complete" still doesn't guarantees that all the JavaScript and Ajax Calls have completed.




To wait for the all the JavaScript and Ajax Calls to complete you can write a function as follows :



public void WaitForAjax2Complete() throws InterruptedException

while (true)

if ((Boolean) ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0"))
break;

Thread.sleep(100);




You can find a detailed discussion in Wait for ajax request to complete - selenium webdriver




Now, the above two approaches through PageLoadStrategy and "return jQuery.active == 0" looks to be waiting for indefinite events. So for a definite wait you can induce WebDriverWait inconjunction with ExpectedConditions set to titleContains() method which will ensure that the Page Title (i.e. the Web Page) is visible and assume the all the elements are also visible as follows :



driver.get("https://www.google.com/");
new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("partial_title_of_application_under_test"));
System.out.println(driver.getTitle());
driver.quit();



Now, at times it is possible though the Page Title will match your Application Title still the desired element you want to interact haven't completed loading. So a more granular approach would be to induce WebDriverWait inconjunction with ExpectedConditions set to visibilityOfElementLocated() method which will make your program wait for the desired element to be visible as follows :



driver.get("https://www.google.com/");
WebElement ele = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element")));
System.out.println(ele.getText());
driver.quit();





share|improve this answer

























  • This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

    – BT101
    Mar 4 at 18:51












  • @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

    – DebanjanB
    Mar 4 at 18:54


















0














I use selenium too and I had the same problem, to fix that I just wait also for the jQuery to load.



So if you have the same issue try this also



((Long) ((JavascriptExecutor) browser).executeScript("return jQuery.active") == 0);


You can wrap both function in a method and check until both page and jQuery is loaded






share|improve this answer























  • You are making an assumption that the website being driven by Selenium uses JQuery...

    – Ardesco
    Mar 13 at 14:24


















0














Implement this, Its working for many of us including me. It includes Web Page wait on JavaScript, Angular, JQuery if its there.



If your Application is containing Javascript & JQuery you can write code for only those,



By define it in single method and you can Call it anywhere:



 // Wait for jQuery to load

ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) driver).executeScript("return jQuery.active") == 0);

boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");

if (!jqueryReady)
// System.out.println("JQuery is NOT Ready!");
wait.until(jQueryLoad);

wait.until(jQueryLoad);


// Wait for ANGULAR to load

String angularReadyScript = "return angular.element(document).injector().get('$http').pendingRequests.length === 0";

ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());

boolean angularReady = Boolean.valueOf(js.executeScript(angularReadyScript).toString());

if (!angularReady)
// System.out.println("ANGULAR is NOT Ready!");
wait.until(angularLoad);



// Wait for Javascript to load

ExpectedCondition<Boolean> jsLoad = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString()
.equals("complete");

boolean jsReady = (Boolean) js.executeScript("return document.readyState").toString().equals("complete");

// Wait Javascript until it is Ready!
if (!jsReady)
// System.out.println("JS in NOT Ready!");
wait.until(jsLoad);




Click here for Reference Link



Let me know if you stuck anywhere by implementing.



It overcomes the use of Thread or Explicit Wait.






share|improve this answer




















  • 1





    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

    – Zabuza
    May 14 '18 at 12:57











  • @Zabuza : Code Added. Thanks.

    – Ishita Shah
    May 14 '18 at 13:18


















0














 public static void waitForPageToLoad(long timeOutInSeconds) 
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>()
public Boolean apply(WebDriver driver)
return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");

;
try
System.out.println("Waiting for page to load...");
WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds);
wait.until(expectation);
catch (Throwable error)
System.out.println(
"Timeout waiting for Page Load Request to complete after " + timeOutInSeconds + " seconds");




Try this method






share|improve this answer






























    0














    Something like this should work (please excuse the python in a java answer):



    idle = driver.execute_async_script("""
    window.requestIdleCallback(() =>
    arguments[0](true)
    )
    """)


    This should block until the event loop is idle which means all assets should be loaded.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50327132%2fdo-we-have-any-generic-funtion-to-check-if-page-has-completely-loaded-in-seleniu%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      As you mentioned if there is any generic funtion to check if page has completely loaded in Selenium the answer is No.



      First let us have a look at your code trial which is as follows :



      new WebDriverWait(firefoxDriver, pageLoadTimeout).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


      The parameter pageLoadTimeout in the above line of code doesn't really reseambles to actual pageLoadTimeout().



      Here you can find a detailed discussion of pageLoadTimeout in Selenium not working




      Now as your usecase relates to page being completely loaded you can use the pageLoadStrategy() set to normal [ the supported values being none, eager or normal ] using either through an instance of DesiredCapabilities Class or ChromeOptions Class as follows :




      • Using DesiredCapabilities Class :



         import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.remote.DesiredCapabilities;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        DesiredCapabilities dcap = new DesiredCapabilities();
        dcap.setCapability("pageLoadStrategy", "normal");
        FirefoxOptions opt = new FirefoxOptions();
        opt.merge(dcap);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();





      • Using ChromeOptions Class :



        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.PageLoadStrategy;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        FirefoxOptions opt = new FirefoxOptions();
        opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();




      You can find a detailed discussion in Page load strategy for Chrome driver (Updated till Selenium v3.12.0)




      Now setting PageLoadStrategy to NORMAL and your code trial both ensures that the Browser Client have (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.



      You can find a detailed discussion in Selenium IE WebDriver only works while debugging



      But the Browser Client attaining 'document.readyState' equal to "complete" still doesn't guarantees that all the JavaScript and Ajax Calls have completed.




      To wait for the all the JavaScript and Ajax Calls to complete you can write a function as follows :



      public void WaitForAjax2Complete() throws InterruptedException

      while (true)

      if ((Boolean) ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0"))
      break;

      Thread.sleep(100);




      You can find a detailed discussion in Wait for ajax request to complete - selenium webdriver




      Now, the above two approaches through PageLoadStrategy and "return jQuery.active == 0" looks to be waiting for indefinite events. So for a definite wait you can induce WebDriverWait inconjunction with ExpectedConditions set to titleContains() method which will ensure that the Page Title (i.e. the Web Page) is visible and assume the all the elements are also visible as follows :



      driver.get("https://www.google.com/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("partial_title_of_application_under_test"));
      System.out.println(driver.getTitle());
      driver.quit();



      Now, at times it is possible though the Page Title will match your Application Title still the desired element you want to interact haven't completed loading. So a more granular approach would be to induce WebDriverWait inconjunction with ExpectedConditions set to visibilityOfElementLocated() method which will make your program wait for the desired element to be visible as follows :



      driver.get("https://www.google.com/");
      WebElement ele = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element")));
      System.out.println(ele.getText());
      driver.quit();





      share|improve this answer

























      • This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

        – BT101
        Mar 4 at 18:51












      • @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

        – DebanjanB
        Mar 4 at 18:54















      3














      As you mentioned if there is any generic funtion to check if page has completely loaded in Selenium the answer is No.



      First let us have a look at your code trial which is as follows :



      new WebDriverWait(firefoxDriver, pageLoadTimeout).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


      The parameter pageLoadTimeout in the above line of code doesn't really reseambles to actual pageLoadTimeout().



      Here you can find a detailed discussion of pageLoadTimeout in Selenium not working




      Now as your usecase relates to page being completely loaded you can use the pageLoadStrategy() set to normal [ the supported values being none, eager or normal ] using either through an instance of DesiredCapabilities Class or ChromeOptions Class as follows :




      • Using DesiredCapabilities Class :



         import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.remote.DesiredCapabilities;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        DesiredCapabilities dcap = new DesiredCapabilities();
        dcap.setCapability("pageLoadStrategy", "normal");
        FirefoxOptions opt = new FirefoxOptions();
        opt.merge(dcap);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();





      • Using ChromeOptions Class :



        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.PageLoadStrategy;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        FirefoxOptions opt = new FirefoxOptions();
        opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();




      You can find a detailed discussion in Page load strategy for Chrome driver (Updated till Selenium v3.12.0)




      Now setting PageLoadStrategy to NORMAL and your code trial both ensures that the Browser Client have (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.



      You can find a detailed discussion in Selenium IE WebDriver only works while debugging



      But the Browser Client attaining 'document.readyState' equal to "complete" still doesn't guarantees that all the JavaScript and Ajax Calls have completed.




      To wait for the all the JavaScript and Ajax Calls to complete you can write a function as follows :



      public void WaitForAjax2Complete() throws InterruptedException

      while (true)

      if ((Boolean) ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0"))
      break;

      Thread.sleep(100);




      You can find a detailed discussion in Wait for ajax request to complete - selenium webdriver




      Now, the above two approaches through PageLoadStrategy and "return jQuery.active == 0" looks to be waiting for indefinite events. So for a definite wait you can induce WebDriverWait inconjunction with ExpectedConditions set to titleContains() method which will ensure that the Page Title (i.e. the Web Page) is visible and assume the all the elements are also visible as follows :



      driver.get("https://www.google.com/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("partial_title_of_application_under_test"));
      System.out.println(driver.getTitle());
      driver.quit();



      Now, at times it is possible though the Page Title will match your Application Title still the desired element you want to interact haven't completed loading. So a more granular approach would be to induce WebDriverWait inconjunction with ExpectedConditions set to visibilityOfElementLocated() method which will make your program wait for the desired element to be visible as follows :



      driver.get("https://www.google.com/");
      WebElement ele = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element")));
      System.out.println(ele.getText());
      driver.quit();





      share|improve this answer

























      • This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

        – BT101
        Mar 4 at 18:51












      • @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

        – DebanjanB
        Mar 4 at 18:54













      3












      3








      3







      As you mentioned if there is any generic funtion to check if page has completely loaded in Selenium the answer is No.



      First let us have a look at your code trial which is as follows :



      new WebDriverWait(firefoxDriver, pageLoadTimeout).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


      The parameter pageLoadTimeout in the above line of code doesn't really reseambles to actual pageLoadTimeout().



      Here you can find a detailed discussion of pageLoadTimeout in Selenium not working




      Now as your usecase relates to page being completely loaded you can use the pageLoadStrategy() set to normal [ the supported values being none, eager or normal ] using either through an instance of DesiredCapabilities Class or ChromeOptions Class as follows :




      • Using DesiredCapabilities Class :



         import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.remote.DesiredCapabilities;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        DesiredCapabilities dcap = new DesiredCapabilities();
        dcap.setCapability("pageLoadStrategy", "normal");
        FirefoxOptions opt = new FirefoxOptions();
        opt.merge(dcap);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();





      • Using ChromeOptions Class :



        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.PageLoadStrategy;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        FirefoxOptions opt = new FirefoxOptions();
        opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();




      You can find a detailed discussion in Page load strategy for Chrome driver (Updated till Selenium v3.12.0)




      Now setting PageLoadStrategy to NORMAL and your code trial both ensures that the Browser Client have (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.



      You can find a detailed discussion in Selenium IE WebDriver only works while debugging



      But the Browser Client attaining 'document.readyState' equal to "complete" still doesn't guarantees that all the JavaScript and Ajax Calls have completed.




      To wait for the all the JavaScript and Ajax Calls to complete you can write a function as follows :



      public void WaitForAjax2Complete() throws InterruptedException

      while (true)

      if ((Boolean) ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0"))
      break;

      Thread.sleep(100);




      You can find a detailed discussion in Wait for ajax request to complete - selenium webdriver




      Now, the above two approaches through PageLoadStrategy and "return jQuery.active == 0" looks to be waiting for indefinite events. So for a definite wait you can induce WebDriverWait inconjunction with ExpectedConditions set to titleContains() method which will ensure that the Page Title (i.e. the Web Page) is visible and assume the all the elements are also visible as follows :



      driver.get("https://www.google.com/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("partial_title_of_application_under_test"));
      System.out.println(driver.getTitle());
      driver.quit();



      Now, at times it is possible though the Page Title will match your Application Title still the desired element you want to interact haven't completed loading. So a more granular approach would be to induce WebDriverWait inconjunction with ExpectedConditions set to visibilityOfElementLocated() method which will make your program wait for the desired element to be visible as follows :



      driver.get("https://www.google.com/");
      WebElement ele = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element")));
      System.out.println(ele.getText());
      driver.quit();





      share|improve this answer















      As you mentioned if there is any generic funtion to check if page has completely loaded in Selenium the answer is No.



      First let us have a look at your code trial which is as follows :



      new WebDriverWait(firefoxDriver, pageLoadTimeout).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));


      The parameter pageLoadTimeout in the above line of code doesn't really reseambles to actual pageLoadTimeout().



      Here you can find a detailed discussion of pageLoadTimeout in Selenium not working




      Now as your usecase relates to page being completely loaded you can use the pageLoadStrategy() set to normal [ the supported values being none, eager or normal ] using either through an instance of DesiredCapabilities Class or ChromeOptions Class as follows :




      • Using DesiredCapabilities Class :



         import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.remote.DesiredCapabilities;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        DesiredCapabilities dcap = new DesiredCapabilities();
        dcap.setCapability("pageLoadStrategy", "normal");
        FirefoxOptions opt = new FirefoxOptions();
        opt.merge(dcap);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();





      • Using ChromeOptions Class :



        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxOptions;
        import org.openqa.selenium.PageLoadStrategy;

        public class myDemo

        public static void main(String[] args) throws Exception

        System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
        FirefoxOptions opt = new FirefoxOptions();
        opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        WebDriver driver = new FirefoxDriver(opt);
        driver.get("https://www.google.com/");
        System.out.println(driver.getTitle());
        driver.quit();




      You can find a detailed discussion in Page load strategy for Chrome driver (Updated till Selenium v3.12.0)




      Now setting PageLoadStrategy to NORMAL and your code trial both ensures that the Browser Client have (i.e. the Web Browser) have attained 'document.readyState' equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.



      You can find a detailed discussion in Selenium IE WebDriver only works while debugging



      But the Browser Client attaining 'document.readyState' equal to "complete" still doesn't guarantees that all the JavaScript and Ajax Calls have completed.




      To wait for the all the JavaScript and Ajax Calls to complete you can write a function as follows :



      public void WaitForAjax2Complete() throws InterruptedException

      while (true)

      if ((Boolean) ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0"))
      break;

      Thread.sleep(100);




      You can find a detailed discussion in Wait for ajax request to complete - selenium webdriver




      Now, the above two approaches through PageLoadStrategy and "return jQuery.active == 0" looks to be waiting for indefinite events. So for a definite wait you can induce WebDriverWait inconjunction with ExpectedConditions set to titleContains() method which will ensure that the Page Title (i.e. the Web Page) is visible and assume the all the elements are also visible as follows :



      driver.get("https://www.google.com/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("partial_title_of_application_under_test"));
      System.out.println(driver.getTitle());
      driver.quit();



      Now, at times it is possible though the Page Title will match your Application Title still the desired element you want to interact haven't completed loading. So a more granular approach would be to induce WebDriverWait inconjunction with ExpectedConditions set to visibilityOfElementLocated() method which will make your program wait for the desired element to be visible as follows :



      driver.get("https://www.google.com/");
      WebElement ele = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element")));
      System.out.println(ele.getText());
      driver.quit();






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 7 at 7:13

























      answered May 14 '18 at 11:20









      DebanjanBDebanjanB

      48.6k144993




      48.6k144993












      • This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

        – BT101
        Mar 4 at 18:51












      • @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

        – DebanjanB
        Mar 4 at 18:54

















      • This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

        – BT101
        Mar 4 at 18:51












      • @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

        – DebanjanB
        Mar 4 at 18:54
















      This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

      – BT101
      Mar 4 at 18:51






      This is JAVA, it doesn't answer question related to js-selenium-webdriver which you marked as dup.

      – BT101
      Mar 4 at 18:51














      @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

      – DebanjanB
      Mar 4 at 18:54





      @BT101 The underlying concept remains the same. Do you feel it would be a good idea to repeat the same answer in 52 different language bindings supported by Selenium?

      – DebanjanB
      Mar 4 at 18:54













      0














      I use selenium too and I had the same problem, to fix that I just wait also for the jQuery to load.



      So if you have the same issue try this also



      ((Long) ((JavascriptExecutor) browser).executeScript("return jQuery.active") == 0);


      You can wrap both function in a method and check until both page and jQuery is loaded






      share|improve this answer























      • You are making an assumption that the website being driven by Selenium uses JQuery...

        – Ardesco
        Mar 13 at 14:24















      0














      I use selenium too and I had the same problem, to fix that I just wait also for the jQuery to load.



      So if you have the same issue try this also



      ((Long) ((JavascriptExecutor) browser).executeScript("return jQuery.active") == 0);


      You can wrap both function in a method and check until both page and jQuery is loaded






      share|improve this answer























      • You are making an assumption that the website being driven by Selenium uses JQuery...

        – Ardesco
        Mar 13 at 14:24













      0












      0








      0







      I use selenium too and I had the same problem, to fix that I just wait also for the jQuery to load.



      So if you have the same issue try this also



      ((Long) ((JavascriptExecutor) browser).executeScript("return jQuery.active") == 0);


      You can wrap both function in a method and check until both page and jQuery is loaded






      share|improve this answer













      I use selenium too and I had the same problem, to fix that I just wait also for the jQuery to load.



      So if you have the same issue try this also



      ((Long) ((JavascriptExecutor) browser).executeScript("return jQuery.active") == 0);


      You can wrap both function in a method and check until both page and jQuery is loaded







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered May 14 '18 at 10:06









      MargonMargon

      42218




      42218












      • You are making an assumption that the website being driven by Selenium uses JQuery...

        – Ardesco
        Mar 13 at 14:24

















      • You are making an assumption that the website being driven by Selenium uses JQuery...

        – Ardesco
        Mar 13 at 14:24
















      You are making an assumption that the website being driven by Selenium uses JQuery...

      – Ardesco
      Mar 13 at 14:24





      You are making an assumption that the website being driven by Selenium uses JQuery...

      – Ardesco
      Mar 13 at 14:24











      0














      Implement this, Its working for many of us including me. It includes Web Page wait on JavaScript, Angular, JQuery if its there.



      If your Application is containing Javascript & JQuery you can write code for only those,



      By define it in single method and you can Call it anywhere:



       // Wait for jQuery to load

      ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) driver).executeScript("return jQuery.active") == 0);

      boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");

      if (!jqueryReady)
      // System.out.println("JQuery is NOT Ready!");
      wait.until(jQueryLoad);

      wait.until(jQueryLoad);


      // Wait for ANGULAR to load

      String angularReadyScript = "return angular.element(document).injector().get('$http').pendingRequests.length === 0";

      ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());

      boolean angularReady = Boolean.valueOf(js.executeScript(angularReadyScript).toString());

      if (!angularReady)
      // System.out.println("ANGULAR is NOT Ready!");
      wait.until(angularLoad);



      // Wait for Javascript to load

      ExpectedCondition<Boolean> jsLoad = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString()
      .equals("complete");

      boolean jsReady = (Boolean) js.executeScript("return document.readyState").toString().equals("complete");

      // Wait Javascript until it is Ready!
      if (!jsReady)
      // System.out.println("JS in NOT Ready!");
      wait.until(jsLoad);




      Click here for Reference Link



      Let me know if you stuck anywhere by implementing.



      It overcomes the use of Thread or Explicit Wait.






      share|improve this answer




















      • 1





        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

        – Zabuza
        May 14 '18 at 12:57











      • @Zabuza : Code Added. Thanks.

        – Ishita Shah
        May 14 '18 at 13:18















      0














      Implement this, Its working for many of us including me. It includes Web Page wait on JavaScript, Angular, JQuery if its there.



      If your Application is containing Javascript & JQuery you can write code for only those,



      By define it in single method and you can Call it anywhere:



       // Wait for jQuery to load

      ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) driver).executeScript("return jQuery.active") == 0);

      boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");

      if (!jqueryReady)
      // System.out.println("JQuery is NOT Ready!");
      wait.until(jQueryLoad);

      wait.until(jQueryLoad);


      // Wait for ANGULAR to load

      String angularReadyScript = "return angular.element(document).injector().get('$http').pendingRequests.length === 0";

      ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());

      boolean angularReady = Boolean.valueOf(js.executeScript(angularReadyScript).toString());

      if (!angularReady)
      // System.out.println("ANGULAR is NOT Ready!");
      wait.until(angularLoad);



      // Wait for Javascript to load

      ExpectedCondition<Boolean> jsLoad = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString()
      .equals("complete");

      boolean jsReady = (Boolean) js.executeScript("return document.readyState").toString().equals("complete");

      // Wait Javascript until it is Ready!
      if (!jsReady)
      // System.out.println("JS in NOT Ready!");
      wait.until(jsLoad);




      Click here for Reference Link



      Let me know if you stuck anywhere by implementing.



      It overcomes the use of Thread or Explicit Wait.






      share|improve this answer




















      • 1





        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

        – Zabuza
        May 14 '18 at 12:57











      • @Zabuza : Code Added. Thanks.

        – Ishita Shah
        May 14 '18 at 13:18













      0












      0








      0







      Implement this, Its working for many of us including me. It includes Web Page wait on JavaScript, Angular, JQuery if its there.



      If your Application is containing Javascript & JQuery you can write code for only those,



      By define it in single method and you can Call it anywhere:



       // Wait for jQuery to load

      ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) driver).executeScript("return jQuery.active") == 0);

      boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");

      if (!jqueryReady)
      // System.out.println("JQuery is NOT Ready!");
      wait.until(jQueryLoad);

      wait.until(jQueryLoad);


      // Wait for ANGULAR to load

      String angularReadyScript = "return angular.element(document).injector().get('$http').pendingRequests.length === 0";

      ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());

      boolean angularReady = Boolean.valueOf(js.executeScript(angularReadyScript).toString());

      if (!angularReady)
      // System.out.println("ANGULAR is NOT Ready!");
      wait.until(angularLoad);



      // Wait for Javascript to load

      ExpectedCondition<Boolean> jsLoad = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString()
      .equals("complete");

      boolean jsReady = (Boolean) js.executeScript("return document.readyState").toString().equals("complete");

      // Wait Javascript until it is Ready!
      if (!jsReady)
      // System.out.println("JS in NOT Ready!");
      wait.until(jsLoad);




      Click here for Reference Link



      Let me know if you stuck anywhere by implementing.



      It overcomes the use of Thread or Explicit Wait.






      share|improve this answer















      Implement this, Its working for many of us including me. It includes Web Page wait on JavaScript, Angular, JQuery if its there.



      If your Application is containing Javascript & JQuery you can write code for only those,



      By define it in single method and you can Call it anywhere:



       // Wait for jQuery to load

      ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) driver).executeScript("return jQuery.active") == 0);

      boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");

      if (!jqueryReady)
      // System.out.println("JQuery is NOT Ready!");
      wait.until(jQueryLoad);

      wait.until(jQueryLoad);


      // Wait for ANGULAR to load

      String angularReadyScript = "return angular.element(document).injector().get('$http').pendingRequests.length === 0";

      ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());

      boolean angularReady = Boolean.valueOf(js.executeScript(angularReadyScript).toString());

      if (!angularReady)
      // System.out.println("ANGULAR is NOT Ready!");
      wait.until(angularLoad);



      // Wait for Javascript to load

      ExpectedCondition<Boolean> jsLoad = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString()
      .equals("complete");

      boolean jsReady = (Boolean) js.executeScript("return document.readyState").toString().equals("complete");

      // Wait Javascript until it is Ready!
      if (!jsReady)
      // System.out.println("JS in NOT Ready!");
      wait.until(jsLoad);




      Click here for Reference Link



      Let me know if you stuck anywhere by implementing.



      It overcomes the use of Thread or Explicit Wait.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 14 '18 at 13:17

























      answered May 14 '18 at 10:56









      Ishita ShahIshita Shah

      2,5221927




      2,5221927







      • 1





        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

        – Zabuza
        May 14 '18 at 12:57











      • @Zabuza : Code Added. Thanks.

        – Ishita Shah
        May 14 '18 at 13:18












      • 1





        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

        – Zabuza
        May 14 '18 at 12:57











      • @Zabuza : Code Added. Thanks.

        – Ishita Shah
        May 14 '18 at 13:18







      1




      1





      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

      – Zabuza
      May 14 '18 at 12:57





      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

      – Zabuza
      May 14 '18 at 12:57













      @Zabuza : Code Added. Thanks.

      – Ishita Shah
      May 14 '18 at 13:18





      @Zabuza : Code Added. Thanks.

      – Ishita Shah
      May 14 '18 at 13:18











      0














       public static void waitForPageToLoad(long timeOutInSeconds) 
      ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>()
      public Boolean apply(WebDriver driver)
      return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");

      ;
      try
      System.out.println("Waiting for page to load...");
      WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds);
      wait.until(expectation);
      catch (Throwable error)
      System.out.println(
      "Timeout waiting for Page Load Request to complete after " + timeOutInSeconds + " seconds");




      Try this method






      share|improve this answer



























        0














         public static void waitForPageToLoad(long timeOutInSeconds) 
        ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>()
        public Boolean apply(WebDriver driver)
        return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");

        ;
        try
        System.out.println("Waiting for page to load...");
        WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds);
        wait.until(expectation);
        catch (Throwable error)
        System.out.println(
        "Timeout waiting for Page Load Request to complete after " + timeOutInSeconds + " seconds");




        Try this method






        share|improve this answer

























          0












          0








          0







           public static void waitForPageToLoad(long timeOutInSeconds) 
          ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>()
          public Boolean apply(WebDriver driver)
          return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");

          ;
          try
          System.out.println("Waiting for page to load...");
          WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds);
          wait.until(expectation);
          catch (Throwable error)
          System.out.println(
          "Timeout waiting for Page Load Request to complete after " + timeOutInSeconds + " seconds");




          Try this method






          share|improve this answer













           public static void waitForPageToLoad(long timeOutInSeconds) 
          ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>()
          public Boolean apply(WebDriver driver)
          return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");

          ;
          try
          System.out.println("Waiting for page to load...");
          WebDriverWait wait = new WebDriverWait(Driver.getDriver(), timeOutInSeconds);
          wait.until(expectation);
          catch (Throwable error)
          System.out.println(
          "Timeout waiting for Page Load Request to complete after " + timeOutInSeconds + " seconds");




          Try this method







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 14 '18 at 14:37









          mbn217mbn217

          45129




          45129





















              0














              Something like this should work (please excuse the python in a java answer):



              idle = driver.execute_async_script("""
              window.requestIdleCallback(() =>
              arguments[0](true)
              )
              """)


              This should block until the event loop is idle which means all assets should be loaded.






              share|improve this answer



























                0














                Something like this should work (please excuse the python in a java answer):



                idle = driver.execute_async_script("""
                window.requestIdleCallback(() =>
                arguments[0](true)
                )
                """)


                This should block until the event loop is idle which means all assets should be loaded.






                share|improve this answer

























                  0












                  0








                  0







                  Something like this should work (please excuse the python in a java answer):



                  idle = driver.execute_async_script("""
                  window.requestIdleCallback(() =>
                  arguments[0](true)
                  )
                  """)


                  This should block until the event loop is idle which means all assets should be loaded.






                  share|improve this answer













                  Something like this should work (please excuse the python in a java answer):



                  idle = driver.execute_async_script("""
                  window.requestIdleCallback(() =>
                  arguments[0](true)
                  )
                  """)


                  This should block until the event loop is idle which means all assets should be loaded.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 3 at 0:12









                  pguardiariopguardiario

                  37.2k1181118




                  37.2k1181118



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50327132%2fdo-we-have-any-generic-funtion-to-check-if-page-has-completely-loaded-in-seleniu%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현