TWebBrowser打开的页面中,如何用程序填写页面中输入框的内容,然后再用程序模拟提交的动作

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Docs, ovElements: OleVariant;
      i: integer;
    begin
      WebBrowser1.Navigate('http://www.csdn.net/member/login.asp');
      while WebBrowser1.ReadyState < READYSTATE_COMPLETE do
        Application.ProcessMessages;  Docs := WebBrowser1.OleObject.Document;
    //-- <input name=login_name ID="login_name">
      ovElements := Docs.GetElementByID('login_name');
      ovElements.Value :='your_UserName';
    //-- <input type=password name=password ID="password">
      ovElements := Docs.GetElementByID('password');
      ovElements.Value :='your_Password';//-- <input type="image" src="/member/images/go.gif">
      ovElements := WebBrowser1.OleObject.Document.all.tags('INPUT');
      for i := 0 to (ovElements.Length - 1) do
        if UpperCase(ovElements.item(i).type) = 'IMAGE' then
          ovElements.item(i).Click;
    end;説明:在上述SOURCE中、輸入NI在CSDN的用户名和密码(或在网页中輸入)
       按「Button1」模擬网页中的動作。