我正在使用以下代码在网站登录表单上各自的字段中填写用户名和密码。
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;
各个字段的信息:
当我运行代码时发生了什么:
如您所见,用户名部分有效,用户名被插入。但是,密码字段没有。
我究竟做错了什么?


