//自动填写主要过程;
procedure TForm1.FillIEForm(aValidatecode: String; bPost: boolean);
procedure DoWithHtmlElement(aElementCollection:IHTMLElementCollection);
var
k:integer;
vk:oleVariant;
Dispatch: IDispatch;
//声明接口;
HTMLInputElement:IHTMLInputElement;
HTMLSelectElement:IHTMLSelectElement;
HTMLOptionElement: IHTMLOptionElement;
HTMLTextAreaElement: IHTMLTextAreaElement;
HTMLFormElement:IHTMLFormElement;
HTMLOptionButtonElement:IHTMLOptionButtonElement;
begin
for k:=0 to aElementCollection.length -1 do//对当前页的所有对象进行循环断定;
begin
Vk:=k;
Application.ProcessMessages;
Dispatch:=aElementCollection.item(Vk,0);
//如果是页面;
if SUCCEEDED(Dispatch.QueryInterface(IHTMLFormElement,HTMLFormElement))then
begin
with HTMLFormElement do//表单
begin
//处理
if bPost then
begin
HTMLFormElement.submit ;//提交所填写的窗体;
exit;
end;
end;
end
//如果是输入框;
else if Succeeded(Dispatch.QueryInterface(IHTMLInputElement,HTMLInputElement)) then
begin
With HTMLInputElement do//单行文本
begin
if (UpperCase(Type_)=''TEXT'') or (UpperCase(Type_)=''PASSWORD'') then//判断输入框类型;
begin
value:=''luowenfu''; //输入名字;
if Name=''Validatecode'' then Value:=aValidatecode;
if Name=''Passwd'' then Value:=''19820128''; //输入密码;
if Name=''Passwd1'' then Value:=''19820128'';
if Name=''e_mail'' then value:=''luowenfu_1982@163.com'';
if Name=''OICQ'' then Value:=''282839896'';
if Name=''width'' then Value:=''40'';
if Name=''height'' then Value:=''40'';
if Name=''myface'' then Value:='''';
end
else if (UpperCase(Type_)=''CHECKBOX'') then//复选框
begin
checked:=true;
end
else if (UpperCase(Type_)=''RADIO'') then//单选框
begin
checked :=true;
end
else if (UpperCase(Type_)=''FILE'') then//选择路径;
begin
HTMLInputElement.defaultValue:=''E:\LWen\Lwen作品\卡片\ExeFile\pic\cat1\3.bmp'';
end;
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLSelectElement,HTMLSelectElement)) then
begin
With HTMLSelectElement do//下拉框
begin
selectedIndex :=1;//默认选择第二个;
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLTEXTAreaElement,HTMLTextAreaElement)) then
begin
with HTMLTextAreaElement do//多行文本
begin
value :=''向别人学习!再教别人学习!!'';
end;
end
else if Succeeded(Dispatch.QueryInterface(IHTMLOptionElement,HTMLOptionElement)) then
begin
with HTMLOptionElement do//下拉选项
begin
//处理
end;
end
else if SUCCEEDED(Dispatch.QueryInterface(IHTMLOptionButtonElement,HTMLOptionButtonElement))then
begin
//不明
//处理
end
else
//showmessage(''other'');
;
end;
end;
var
HTMLDocument:IHTMLDocument2;//可修改文档;
ElementCollection:IHTMLElementCollection;
Dispatch: IDispatch;
i,j:integer;
FrameWindow:IHTMLWindow2;//框架窗口;
Vi,Vj:OLEVariant;
HTMLFrameBase :IHTMLFrameBase ;
HTMLFrameElement:IHTMLFrameElement ;
HTMLIFrameElement:IHTMLIFrameElement;
begin
HTMLDocument:=IHTMLDocument2(WebBro1.Document);//指定要修改的文档;
if HTMLDocument<>nil then
begin
begin
if HTMLDocument.frames.length =0 then//如果是无框架
begin
ElementCollection:=HTMLDocument.Get_All;
DoWithHtmlElement(ElementCollection);//调用填写过程;
end
else//有框架
begin
//先填写当前页;
ElementCollection:=HTMLDocument.Get_All