老问题了,参见:
// 填写
var
HtmlDoc:IHTMLDocument2;
InputText1,InputText2,InputText3,InputText4,InputText5:IHTMLInputTextElement; // Edit框
TypeElement:variant;
I:Integer;
begin
webbrowser1.Navigate(edit1.Text);
exit;
HtmlDoc:=WebBrowser1.Document as IHTMLDocument2;
for i:=0 to HtmlDoc.all.length-1 do
begin
TypeElement:=Htmldoc.all.item(i,varempty);
if Uppercase(TypeElement.tagName)='INPUT' then
begin
if Uppercase(TypeElement.type)='TEXT' then // 填 Edit 框
begin
InputText1:=HtmlDoc.all.item(i,varempty) as IHTMLInputTextElement;
if InputText1.name='username' then InputText1.value:='abc';
InputText4:=HtmlDoc.all.item(i,varempty) as IHTMLInputTextElement;
if InputText4.name='email' then InputText4.value:='xxxx@163.com';
InputText5:=HtmlDoc.all.item(i,varempty) as IHTMLInputTextElement;
if InputText5.name='url' then InputText5.value:='http://www.xxx.com';
end;
if Uppercase(TypeElement.type)='PASSWORD' then // 填密码框
begin
InputText2:=HtmlDoc.all.item(i,varempty) as IHTMLInputTextElement;
if InputText2.name='password' then InputText2.value:='12345678';
InputText3:=HtmlDoc.all.item(i,varempty) as IHTMLInputTextElement;
if InputText3.name='password2' then InputText3.value:='12345678';
end;
end;
end;
end;
// 提交
var
HtmlDoc:IHTMLDocument2;
myitem:Olevariant;
i:integer;
begin
myitem := WebBrowser1.Document;
for i := 0 to myitem.all.length - 1 do
begin
if myitem.all.item(i).tagName = 'INPUT' then
if Uppercase(myitem.all.item(i).type)='SUBMIT' then
if Uppercase(myitem.all.item(i).name)='OK' then
myitem.all.item(i).click;
end;
end;