webBrowser 模拟鼠标点击问题
procedure TForm1.Button3Click(Sender: TObject);
var
Doc:IHTMLDocument2;
UserName:IHTMLInputElement;
Password: IHTMLInputElement;
begin
wb.Navigate('http://www.xxx.com/login/');
while wb.ReadyState<>4 do
Application.ProcessMessages;
FUserName := GetUserName; //获取用户名
if FUserName <> '' then
begin
Doc := wb.Document as IHTMLDocument2;
UserName := Doc.all.item('username',varEmpty) as IHTMLInputElement;
UserName.value:=FUserName;
Password := Doc.all.item('password',varEmpty) as IHTMLInputElement;
Password.value := '530251';
end;
Wb.OleObject.document.getElementsByTagName('input').item(2).click; //登录的序号
wb.Navigate('www.xxx.com/xxxx'); //转到其他页面
Wb.OleObject.document.getElementsByTagName('input').item(3).click; //新页面的button的序号
end;
执行会出现错误:Access violation at address 004657CDF in module 'test.exe'. Read of address 00000000
如果把上面最后一句:
Wb.OleObject.document.getElementsByTagName('input').item(3).click;
放在另一个Button里执行就不会出错。
请问放在同一个Button的单击事件里,要怎么写才不会出错