TWebBrowserの検索結果から「次へ」のボタンを自動的にクリックする方法は?


大貫  2010-08-05 06:12:25  No: 38926

WebBrowserを使って検索プログラムを作っています。指定サイトを開いて検索を行う迄は以下のソースの様に出来るのですが、良くあるブラウザー内の「次へ」ボタンを自動的にクリックする事が出来ません・・・解る方がいらっしゃいましたらお教え下さい。

procedure TForm1.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate(http://sample.co.jp);
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  s     :String;
  iDoc  :IHtmlDocument2;
  I     :integer;
  ov    :OleVariant;
  iDisp :IDispatch;
  iColl :IHTMLElementCollection;
  iInputElement: IHTMLInputElement;
begin
  WebBrowser1.ControlInterface.Document.QueryInterfaceIID_IHTMLDocument, iDoc);
  if not assigned(iDoc) then
    Exit;
  ov := 'INPUT';
  IDisp := iDoc.all.tags(ov);
  if assigned(IDisp) then
  begin
    IDisp.QueryInterface(IID_IHTMLElementCollection, iColl);
    if assigned(iColl) then
    begin
      for I := 1 to iColl.Get_length do
      begin
        iDisp := iColl.item(pred(I), 0);
        iDisp.QueryInterface(IID_IHTMLInputElement, iInputElement);
        if assigned(iInputElement) then
        begin
        if (iInputElement.type_='text') and (InputElement.name='login') then
            iInputElement.value:= UserName;
          if (iInputElement.type_= 'password') and (iInputElement.name='passwd') then
            iInputElement.value:= Password;
          if (iInputElement.type_= 'login') then
          begin
            IsLogin := True;
            iInputElement.form.submit;
          end;
        end;
      end;
    end;
  end;
end;


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加