这篇文章也不算是原创,毕竟参考了某位大牛代码,好了废话不说了直接代码了:
登录前:
登陆后:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, UIWebBrowser, MSHtml, StdCtrls, WinSkinData,
bsSkinData, BusinessSkinForm;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
UIWebBrowser1: TUIWebBrowser;
SkinData1: TSkinData;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
//UiWebBrowser1.Navigate('http://localhost/User/Login.asp');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Doc: IHTMLDocument2;
userinputelement, pwdinputelement: ihtmlinputelement;
begin
doc := UiWebBrowser1.document as ihtmldocument2;
userinputelement := (doc.all.item('name', 0) as ihtmlinputelement);
userinputelement.value := Trim(Edit1.Text);
pwdinputelement := (doc.all.item('password', 0) as ihtmlinputelement);
pwdinputelement.value := Trim(Edit2.Text);
// 下面三种都可以,自己测试
//按按钮名称来点击
//wb1.OleObject.document.all.item('btnLogin').click;
//按钮钮ID来点击
// wb1.OleObject.document.getElementByID('btnLogin').click ;
//按第几个按钮来点击
//UiWebBrowser1.OleObject.document.getElementsByTagName('Input').item(4).click;
UIWebBrowser1.OleObject.Document.all.item('submit').Click;
Label1.Visible := False;
Edit1.Visible := False;
Label2.Visible := False;
Edit2.Visible := False;
Button2.Visible := False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
UiWebBrowser1.Navigate('http://localhost/User/Login.asp');
end;
end.