Delphi click button on the web page

Source: Internet
Author: User

 

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, olectrls, shdocvw;

Type
Tform1 = Class (tform)
Webbrowser1: twebbrowser;
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Procedure formcreate (Sender: tobject );
Procedure button1click (Sender: tobject );
Procedure button4click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

Procedure tform1.formcreate (Sender: tobject );
Begin
Webbrowser1.align: = altop;
Button2.enabled: = false;
Button3.enabled: = false;
Button4.enabled: = false;
Button1.caption: = 'simulate A page ';
Button2.caption: = 'let's know the button name ';
Button3.caption: = 'let's know the button id ';
Button4.caption: = 'Suppose you only know the buttons ';
End;

{Simulate a page}
Procedure tform1.button1click (Sender: tobject );
Begin
Webbrowser1.navigate (
'About: '<Form method = "Post" Action = "http://www.nobird.org/">' +
'<Input type = "Submit" value = "Submit" id = "btnid" name = "btnname">' +
'</Form> </body> ');
Button2.enabled: = true;
Button3.enabled: = true;
Button4.enabled: = true;
End;

{If you know the button name, for example, btnname}
Procedure tform1.button2click (Sender: tobject );
Begin
Webbrowser1.oleobject.doc ument. All. Item ('btnname'). Click;
// Webbrowser1.oleobject.doc ument. All. Item ('btnname', 0). Click;
Formcreate (NiL );
End;

{If you know the button ID, for example, btnid}
Procedure tform1.button3click (Sender: tobject );
Begin
Webbrowser1.oleobject.doc ument. getelementbyid ('btnid'). Click;
Formcreate (NiL );
End;

{If you only know the button number, for example, the first button}
Procedure tform1.button4click (Sender: tobject );
Begin
Webbrowser1.oleobject.doc ument. getelementsbytagname ('input'). Item (0). Click;
Formcreate (NiL );
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.