我正在使用下面的代码来填写一个用户名和密码到他们各自的网站登录表单中的字段。TWebBrowser自动登录
var
Doc: IHTMLDocument2;
I: Integer;
Element: OleVariant;
Elements: IHTMLElementCollection;
Sub: Variant;
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
Elements := Doc.All;
for I := 0 to Elements.length - 1 do begin
Element := Elements.item(I, varEmpty);
if (UpperCase(Element.tagName) = 'INPUT') and (UpperCase(Element.Type) = 'TEXT') then begin
if (Element.name = 'user') then Element.value := 'theusername';
if (UpperCase(Element.tagName) = 'INPUT') and (UpperCase(Element.Type) = 'PASSWORD') then begin
if (Element.name = 'passwrd') then Element.value := 'thepassword';
end;
end;
Sub := WebBrowser1.Document;
Sub.frmLogin.Submit();
end;
end;
信息在各自的领域:
当我运行的代码发生了什么事:
正如你所看到的,用户名部分作品,用户名被插入。密码字段,但是,不。
我在做什么错?
'大写(Element.tagName)= 'input''和下一个看起来不正确 - 'UpperCase'赢得' T匹配'输入' – BrakNicku
@BrakNicku编辑与代码的问题,我的一个错字,对此感到遗憾。无论哪种方式,它不起作用,有或没有大写字母等,同样的事情发生。 – Petzy
只有第一个(外)'IF'被检查循环中的每一次 – BrakNicku