var
Doc:IHTMLDocument2;
Form:IHTMLFormElement;
begin
Doc:=Webbrowser1.Document as IHTMLDocument2;
Form:= Doc.all.item('Login',0) as IHTMLFormElement;
Form.Submit;
end;
var
Doc:IHTMLDocument2;
Button:IHTMLElement;
begin
Doc:=Webbrowser1.Document as IHTMLDocument2;
Button:= Doc.all.item('MyButton',0) as IHTMLElement;
//如果name和id不存在,即tagName不存在,就要将'MyButton'换成相应序号数字!
Button.click;
end;
调用脚本!
var
Doc:IHTMLDocument2;
Scripts:IHTMLScriptElement;
begin
Doc:=Webbrowser1.Document as IHTMLDocument2;
Scripts:=Doc.scripts.item(0,0) as IHTMLScriptElement;
//Scripts.text可获得脚本内容,Doc.scripts.Length长度,可用于遍历所有脚本!
end;
不过看来,你是想通过外部一个不相关的程序对IE进行控制!这里详细介绍另一种方法,利用IShellWindows接口!首先安装一个ActiveX控件-Microsoft Shell Controls and Automation(IE4以后,系统都自带了)!安装完后,给程序加上TShell控件!
Uses 中加上这些单元ActiveX,MSHTML,OleCtrls,SHDocVw!
var
ShWin:IShellWindows;
Wb:IWebBrowser2;
begin
ShWin:=Shell1.windows as IShellWindows;
Wb:=ShWin.Item(0) as IWebBrowser2;
end;
这样就把第一个IE和Wb相关联!然后利用IHTMLDocument2接口!
var
Doc:IHTMLDocument2;
Button:IHTMLElement;
begin
Doc:=Wb.document as IHTMLDocument2;
Button:= Doc.all.item('MyButton',0) as IHTMLElement;
//如果网页中该按钮的name或id都不存在,即tagName不存在,就要将'MyButton'换成相应序号数字!
Button.click;
//实现点击操作!
end;