DocumentComplete issues

Hi
I am trying to execute a code where I click the “go” button when the following page is done loading: http://www.derivative-calculator.net/#expr=2x+5
However, the code is fired too early, when the page is not fully loaded (maybe because of advertisements and such).

As a result, I get this error

Can anyone think of a way I can overcome this and make sure that the page has been completely loaded before the code is executed?

Edit: I also tested msgbox(Status) at document complete event. I get over 10 message boxes saying “done”.

Add a timer to your project to click the button with a period of say 5000 (5s). Start this timer with mode single when you get your page & set it again with each document complete which will restart the timer. The result will be that after 5s of no document completes your button will be clicked. You’ll probably have to tweak the period of the timer.

Not ideal, but a workaround.

[quote=89087:@Wayne Golding]Add a timer to your project to click the button with a period of say 5000 (5s). Start this timer with mode single when you get your page & set it again with each document complete which will restart the timer. The result will be that after 5s of no document completes your button will be clicked. You’ll probably have to tweak the period of the timer.

Not ideal, but a workaround.[/quote]

I’m assuming this would be different for each computer (so it won’t work in my scenerio). Like, some computers will load the browser faster than the other so I can’t really have a timer… Is it possible for me to check if a certain something has been loaded in the HTML source code, if it has, the majority of the page has been loaded? Like, if html.contains “something”, then execute the code.

I’m sort of curious as to why you’re manipulating the DOM rather than loading the page with the answer?

HTMLViewer1.LoadURL("http://www.derivative-calculator.net/#expr=" + EncodeURLComponent(TextField1.Text))

Where TextField1 is your formula and the supplied code is in a button action event.

You can get the project here

I would set the timer at the END of the DocumentComplete event. Set the timer to say 1 second (YMMV) with and set it to fire with timer.mode single at the end of the event. Then no matter how fast/slow the browser loads, your code will be certain to fire at some point after the event is done.

@Wayne Golding

That’s exactly what I am doing, but you still have to manually press the “Go” button. It doesn’t directly lead to the steps at the button (until the go button is pressed) for some odd reason. The whole point of this is so that I can press the go button after everything is loaded, if I press it too early, I get that error.

[quote=89086:@James Defier]Can anyone think of a way I can overcome this and make sure that the page has been completely loaded before the code is executed?
[/quote]

I added each URL in CancelLoad when I use LoadURL(": http://www.derivative-calculator.net/#expr=2x+5 ").

As a matter of fact, documentcomplete is probably fired each time cancelload is called, which makes a bunch of times.

http://www.derivative-calculator.net/#expr=2x+5 http://www.derivative-calculator.net/# about:blank about:blank http://static.ak.facebook.com/connect/xd_arbiter/dgdTycPTSRj.js?version=41#channel=f36d6e29a&origin=http%3A%2F%2Fwww.derivative-calculator.net https://s-static.ak.facebook.com/connect/xd_arbiter/dgdTycPTSRj.js?version=41#channel=f36d6e29a&origin=http%3A%2F%2Fwww.derivative-calculator.net https://apis.google.com/_/+1/fastbutton?usegapi=1&annotation=bubble&width=150&origin=http%3A%2F%2Fwww.derivative-calculator.net&url=http%3A%2F%2Fwww.derivative-calculator.net%2F&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.rvpQlI-iuYI.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Fz%3Dzcms%2Frs%3DAItRSTOlpd6Caurcj1h4xfVCciTUJfihkw#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Conload&id=I0_1400405792739&parent=http%3A%2F%2Fwww.derivative-calculator.net&pfname=&rpctoken=28167627 https://accounts.google.com/o/oauth2/postmessageRelay?parent=http%3A%2F%2Fwww.derivative-calculator.net#rpctoken=326563990&forcesecure=1 about:blank http://www.facebook.com/plugins/like.php?app_id=545872075478375&channel=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2FdgdTycPTSRj.js%3Fversion%3D41%23cb%3Df2433c7894%26domain%3Dwww.derivative-calculator.net%26origin%3Dhttp%253A%252F%252Fwww.derivative-calculator.net%252Ff36d6e29a%26relation%3Dparent.parent&href=https%3A%2F%2Fwww.facebook.com%2Fpages%2FDerivative-Calculator%2F155912707861825&layout=button_count&locale=de_DE&sdk=joey&send=false&show_faces=false&width=150 https://apis.google.com/u/0/_/+1/fastbutton?usegapi=1&annotation=bubble&width=150&origin=http%3A%2F%2Fwww.derivative-calculator.net&url=http%3A%2F%2Fwww.derivative-calculator.net%2F&gsrc=3p&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.rvpQlI-iuYI.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Fz%3Dzcms%2Frs%3DAItRSTOlpd6Caurcj1h4xfVCciTUJfihkw#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Conload&id=I1_1400405796422&parent=http%3A%2F%2Fwww.derivative-calculator.net&pfname=&rpctoken=17377725

Solution : cancel load of all that filth and keep only the first URL that you instructed.

Function CancelLoad(URL as String) As Boolean if deja = true then return true deja = true TextArea1.Text = TextArea1.Text+url+endofline End Function

Deja is a boolean window property.

Maybe you want to track URLs in CancelLoad and click “Go” only after you find a significant substring in the URL that indicates it is the last one. For instance “www.derivative-calculator.net&pfname=&rpctoken=” apparently found only in the last cancelload.

Something like this in the opening of CancelLoad will set the boolean window property lastURL to true, so you can click “Go”.

if instr(url,"www.derivative-calculator.net&pfname=&rpctoken=")>0 then lasturl = true

:slight_smile: