3
$\begingroup$

There isn't much tuning freedom available in the WebExecute method. If a page takes too long to load you only see a spinner or a blank for CapturePage. Does someone see how to let the method wait a bit?

$\endgroup$
  • $\begingroup$ Adding a manual Pause[] in between WebExecute["OpenPage"] and WebExecute["CapturePage"] could be a possible solution, but I'm not sure if you're looking for something more elegant than that. For websites I've looked at the WebExecute["OpenPage"] command only returns once the page is loaded. Can you give an example of a website that returns but then takes addition time to load other elements of the page? $\endgroup$ – Brady Hunt Apr 18 at 14:48
3
$\begingroup$

This is an unavoidable problem due to the nature of the modern web. You never know when a page has finished loading, because modern websites have Javascripts that just continuously refresh the page, so some websites will not have loaded completely after WebExecute returns from "OpenPage". When WebExecute returns, there's still a possibility that scripts change the page. The only thing you can really do, is use

WebExecute[session, "OpenPage" -> url];
Pause[n]
WebExecute[session, "CapturePage"]

to wait for a while and give the scripts on the page time to stabilize.

$\endgroup$
3
$\begingroup$

At a slight tweak on Sjoerd's solution, you can execute any JavaScript on the page to see if a particular document state has been reached (modern web pages are almost never 'static' so you have to do something more specific to ascertain you are in the state you want to capture an image of):

result = WebExecute[session, "JavaScriptExecute" -> "... javascript code..."]

And then make a decision based on what result is.

$\endgroup$
  • 1
    $\begingroup$ Will consider Sjoerd's proposal as the solution, since it does CapturePage without extra JavaScript. Thanks for the suggestion though. $\endgroup$ – Francois Vanderseypen Apr 18 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.