TWebbrowser load html pages (forms) in sequence

1

I have a TWebBrowser component in the form that loads a page html (a Form ), automatically populates the data and sends it through the

WebBrowser1.OleObject.Document.all.Item('enviar', 0).Click;

After the response page loads, the program analyzes the information on the page (which is the second part of the form) and I make the same command to send that second form.

When I isolate the events in two buttons , everything works correctly, but joining the commands in the same sequence gives a fatal error.

I have tried to use a Sleep(4000) after the 1st sequence to give time to load the page of the second Form , but it still gives error.

Any suggestions?

Code snippet:

WebBrowser1.OleObject.Document.all.Item('login', 0).value := 'usuario';
WebBrowser1.OleObject.Document.all.Item('senha', 0).value := 'senha';
WebBrowser1.OleObject.Document.all.Item('enviar', 0).Click;

Sleep(4000);

.... Processamento dos dados ....

WebBrowser1.OleObject.Document.all.Item('enviar2', 0).Click;
    
asked by anonymous 11.01.2016 / 19:27

1 answer

1

You can apply a Real hold procedure instead of using Sleep , ie you do not know how long the component will take to deliver the result, so we make a cat jump that you can usually solve and deliver on same moment or in milliseconds after!

Please note:

  while WebBrowser1.ReadyState < READYSTATE_INTERACTIVE do
    Application.ProcessMessages;

While the Browser is busy .... We have the Edit Messages application.

Another additional to the answer, you can explore the events of the component, we have OnDocumentComplete which does pretty much the same thing!

Take the tests,

    
11.01.2016 / 19:43