# WebExecute timeout

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?

• 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? – Brady Hunt Apr 18 '19 at 14:48

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.

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.

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