請問有沒有辦法用編程模擬按下已打開的IE網頁上的某一按鈕?
我要打開的是真實的IE,而不是使用webbrowser控件.
ie:=CreateOleObject('InternetExplorer.Application');
ie.Visible:=true;
ie.Navigate('http://www.server.com');
...
....

解决方案 »

  1.   

    uses shellapiShellExecute(Handle,0,'http://www.csdn.net','','',SW_SHOWNORMAL);
    //在默认浏览器中打开
      

  2.   

    我是要用編程執行按下網頁裡的按鈕.
    比如http://mail.163.com/上的'登錄'按鈕
      

  3.   

    转贴的:
    ------------------------------------------------
    一个刷屏软件的原理:  procedure TForm1.Button1Click(Sender:TObject);
      var
        sw:IShellWindows;
        n:integer;
        disp:IDispatch;
        i:integer;
        vi:OleVariant;
        ie1:IWebBrowser2;
        idoc1:IHTMLDocument2;
      begin
        sw:=CoShellWindows.Create;
        n:=sw.count;
        for i:=0 to n-1 do
        begin
          vi:=i;
          disp:=sw.item(vi);
          disp.QueryInterface(IWebBrowser2,ie1);
          if ie1 <> nil then 
              begin
              memo1.lines.add’Location:’+ie1.LocationName);
              ie1.Document.QueryInterfaceIHTMLDocument2,idoc1);
              if idco1 <> nil then 
                begin
                  if idoc1.activeitem.isEditText then            
                    begin
                        idoc1.activeitem.innertext:=’Hello,I GOT YOU!’;
                        keybd_event(VK_RETURN,0,0,0);  // 送回车
                  //当然也是可以找到具体的submit按钮的,调用submit好象安全一点。
                    end;
                  memo1.lines.add(’Title:’+idoc1.Title);
                  memo1.lines.add(’URL:’+idco1.url);
                end; 
            end;
          end;
    end;
      

  4.   

    可以调用InternetExplorer Object的内置方法:procedure TForm1.Button1Click(Sender: TObject);
    var
      ie : olevariant;
      vaIn,vaOut: OleVariant;
    begin
      ie:=CreateOleObject('InternetExplorer.Application');
      ie.Visible:=true;
      ie.Navigate('http://www.applevb.com');  while ie.Busy do
        application.ProcessMessages;  ie.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
    end;需要再uses中引用ComObj, shdocvw, mshtml 这几个单元。
      

  5.   

    用WEBBROWSER就可以了  WEBBROWSER.Navigate('http://www.applevb.com');
      

  6.   

    請問 TechnoFantasy:
    ie.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);有何作用?
    有一網頁的源碼如下,怎樣用編程實現按下'url'這按鈕?(不用webbrowser)
    </head>
    </body> 
    <input type=button value="url" onclick="window.location.href='http://www.163.com';">
    </body>
    </html>
      

  7.   

    找到IE页面中的按钮--------------------------------------------------------------unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,mshtml, OleCtrls, SHDocVw;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender:TObject);
    var
        sw:IShellWindows;
        n:integer;
        disp:IDispatch;
        i:integer;
        vi:OleVariant;
        ie1:IWebBrowser2;
        idoc1:IHTMLDocument2;    j: Integer;
        spDisp:IDispatch;
        aInputButtonText : IHTMLInputButtonElement;
    begin
        sw:=CoShellWindows.Create;
        n:=sw.count;
        for i:=0 to n-1 do
        begin
          vi:=i;
          disp:=sw.item(vi);
          disp.QueryInterface(IWebBrowser2,ie1);
          if ie1 <> nil then
              begin
              memo1.lines.add(' Location:'+ie1.LocationName);
              ie1.Document.QueryInterface(IHTMLDocument2,idoc1);
              if idoc1 <> nil then
                begin
                  for j:=0 to idoc1.all.Length-1do
                  begin
                      spDisp := idoc1.all.item(j,varEmpty);
                      if SUCCEEDED(spDisp.QueryInterface(IHTMLInputButtonElement,
    aInputButtonText )) then
                        if aInputButtonText.value <>'' then
                        begin
                           //keybd_event(VK_RETURN,0,0,0);//发送回车
                           memo1.lines.Add(' Title:'+aInputText.value);
                        end;
                  end;
                end;
            end;
          end;
    end;end.
      

  8.   

    可以找到網頁上的按鈕,但無法模擬按下它呀?
    已修改
    if aInputButtonText.value <>'' then
                        begin
                           keybd_event(VK_RETURN,0,0,0););//发送回车
                           memo1.lines.Add(' Title:'+aInputButtonText.value);
                        end;
    執行後程序是向自己發送'回車'按鈕,而不是向網頁發送?
    請再指教.
      

  9.   

    if aInputButtonText.type_ = 'submit' then
       aInputButtonText.Form.submit;
      

  10.   

    还可以用aInputButtonText.Invoke调用IHTMLButtonElement的click方法,
    不过本人没有试过
      

  11.   

    再請問一下如何向網頁上的文本框直接輸入字串?
    有一網頁源碼如下,能否向'選擇檔案'的文本框裡直接輸入字串?如果不能又如何模擬按下'type=file'的按鍵呢?謝謝.
    <center><h2>上傳檔案</h2></center>
    <form ENCTYPE="multipart/form-data" method=post action="/cgi-bin/upload.cgi">
    <center>選擇檔案: <input type=file name="uploaded_file">
    <input type=hidden name="directory" value="/mnt/web_m/cgi-bin/upload/">
    <input type=submit value="上傳">
    </form></center>
      

  12.   

    把上面代码中的IHTMLInputButtonElement
    换成IHTMLInputElement就是文本框去MSDN或者在google里用IHTMLInputElement作为关键字,
    搜一下看看,有很多这方面的资料var
       aTnput : IHTMLInputElement;.......
    if SUCCEEDED(spDisp.QueryInterface(IHTMLInputButtonElement,
    aTnput )) then
    if aTnput.name='uploaded_file' then 
    aTnput.value='E;\aaaaa.txt';
      

  13.   

    此源碼可用於type="text",type="password"的文本框,但對於type="file"無效,你試過嗎?
    我想可否模擬按下'瀏覽'按鈕後,在選擇檔案的對話框自動輸入文件的路徑,確定後再按網頁上的上傳按鈕,請問一下如何模擬按下'瀏覽'按鈕?
    謝謝.