在TWebbrowser 中模拟点击一个图片提交按钮

来源:互联网 发布:星光大道网络直播 编辑:程序博客网 时间:2024/05/16 04:55

原文我曾在大富翁我的笔记发表,没对外(发表日期:2003-6-29 4:18:00 ),今天略作改动.

http://www.delphibbs.com/keylife/iblog_show.asp?xid=1316

//------------------------------------------------------------------------------------------------------------------------

uses
  MSHTML; //必须引用这个单元

var
  iDoc: IHtmlDocument2;
  i: integer;
  ov: OleVariant;
  iDisp: IDispatch;
  iColl: IHTMLElementCollection;
  InputImage: HTMLInputImage;

//-----------------form http://blog.csdn.net/laoli/----------------------
begin
  WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, iDoc);
  if not Assigned(iDoc) then
  begin
    Exit;
  end;
  ov := 'INPUT'; //------------数据输入容器的对象
  iDisp := iDoc.all.tags(ov);
  if Assigned(IDisp) then
  begin
    IDisp.QueryInterface(IHTMLElementCollection, iColl);
    if Assigned(iColl) then
    begin
      for i := 1 to iColl.Get_length do
      begin
        iDisp := iColl.item(pred(i), 0);
        iDisp.QueryInterface(HTMLInputImage, InputImage);
        if Assigned(InputImage) then
        begin
          if InputImage.Name = '提交' then
          // ---------------------------------------如果按钮名是'提交',就填提交,否则填其他

          begin
            InputImage.Click;  // ------------模拟点击

          end;
        end;
      end;
    end;
  end;
end;  

//------------------------------转载请注名出处和作者,谢谢--------------------------------------------------------

原创粉丝点击