1

Tried Page.onLoadFinished and this function also.

But for some websites its not waiting till the page is fully loaded. Is there any other way i can achieve this?

 function checkReadyState() {
    setTimeout(function () {
        var readyState = page.evaluate(function () {
            return document.readyState;
        });
enter code here
        if ("complete" === readyState) {
           //create screenshot
        } else {
            checkReadyState();
        }
    });
}
checkReadyState();

Please help.

Ajeet Lakhani
  • 3,768
  • 2
  • 22
  • 37
  • Have you tried [this](http://stackoverflow.com/a/21401636/1816580)? There are many definitions of a page load and PhantomJS honors one of them. If it does not correspond to your expected page load, then you should describe what you expect in your question. – Artjom B. Apr 10 '15 at 22:41

1 Answers1

0

The onLoadFinished event is triggered when the whole dom of the page has been loaded but if some javascript on the page dynamically loads some more resources or does some XHR calls you will have to watch the DOM.

You can have a look at CasperJS which is written on top of phantomJS and has some waitForSelector methods for example to wait for a specific element to appear in the dom or waitForResource if you want to wait for a specific external resource.

You can also check this answer that shows how to implement such a feature with plain PhantomJS.

Community
  • 1
  • 1
Tristan Foureur
  • 1,647
  • 10
  • 23
  • The link which you have given in answer is just wait till particular elment is visible. What i am doing is that, waiting till whole page is loaded(all scripts an images) then capture screenshot. – Ajeet Lakhani Apr 11 '15 at 09:36