如果你知道文本框的名字的话,你可以使用下面的代码:procedure TForm1.Button2Click(Sender: TObject); var Doc: IHTMLDocument2; Form : IHTMLFormElement; Elements: IHTMLElementCollection; InputElem : IHTMLInputElement; i : Integer; begin Doc := wbIE.Document as IHTMLDocument2; Elements := Doc.Forms as IHTMLElementCollection; Form := Elements.Item(0,varEmpty) as IHTMLFormElement; Elements := (Doc.All as IHTMLElementCollection).tags('input') as IHTMLElementCollection; for i := 0 to Elements.length-1 do begin InputElem := Elements.Item(i, varEmpty) as IHTMLInputElement; if UpperCase(Trim(InputElem.name)) = 'Name' then InputElem.Value := 'aaa'; if UpperCase(Trim(InputElem.name)) = 'Password' then InputElem.Value := 'bbb'; end; for i := 0 to Elements.length-1 do begin InputElem := Elements.Item(i, varEmpty) as IHTMLInputElement; if UpperCase(Trim(InputElem.type_)) = 'submit' then (InputElem as IHTMLInputButtonElement).form.submit;// := 'bbb'; end; passwor)end;上面的代码填充wbIE中的页面中的name和password两个文本框。
var
Doc: IHTMLDocument2;
Form : IHTMLFormElement;
Elements: IHTMLElementCollection;
InputElem : IHTMLInputElement;
i : Integer;
begin
Doc := wbIE.Document as IHTMLDocument2;
Elements := Doc.Forms as IHTMLElementCollection;
Form := Elements.Item(0,varEmpty) as IHTMLFormElement;
Elements := (Doc.All as IHTMLElementCollection).tags('input') as IHTMLElementCollection;
for i := 0 to Elements.length-1 do
begin
InputElem := Elements.Item(i, varEmpty) as IHTMLInputElement; if UpperCase(Trim(InputElem.name)) = 'Name' then
InputElem.Value := 'aaa';
if UpperCase(Trim(InputElem.name)) = 'Password' then
InputElem.Value := 'bbb';
end; for i := 0 to Elements.length-1 do
begin
InputElem := Elements.Item(i, varEmpty) as IHTMLInputElement; if UpperCase(Trim(InputElem.type_)) = 'submit' then
(InputElem as IHTMLInputButtonElement).form.submit;// := 'bbb';
end;
passwor)end;上面的代码填充wbIE中的页面中的name和password两个文本框。