Twebbrowser load html pages (Forms) in sequence

Asked

Viewed 874 times

1

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

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

After the reply page loads, the program analyzes the page information (which is the second part of the form) and I do the same command to send this second form.

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

I’ve tried using one Sleep(4000) after the first sequence to allow time to load the second page Form, but keeps making a mistake.

Any suggestions?

Excerpt from the code:

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;

1 answer

1

You can apply a Real hold procedure instead of using the Sleep, that is, you do not know how long the component will take to deliver the result, so we do a cat jump that usually manages to resolve and deliver at the same time or in milliseconds after!

Observe:

  while WebBrowser1.ReadyState < READYSTATE_INTERACTIVE do
    Application.ProcessMessages;

While Browser is busy.... We send the Process Messages app.

Another additional to the answer, you can explore the component events, we have the OnDocumentComplete who does practically the same thing!

Run the tests,

  • It didn’t work, it kept giving fatal error. But working with the OnDocumentComplete and with the help of an accountant (the event seems to occur twice) I managed to solve. Thank you.

  • If he used the OnDocumentComplete then resolved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.