procedure TForm1.Button1Click(Sender: TObject);
begin
  web.Navigate('mail.163.com');
  (((web.Document as IHTMLDocument2).body.all as
  IHTMLElementCollection).item('username',0) as IHTMLTextAreaElement).value:='a';   //错在这行  (((web.Document as IHTMLDocument2).body.all as
  IHTMLElementCollection).item('password',0) as IHTMLTextAreaElement).value :='b'
end;这样写的,不知道摸拟点登陆按钮要怎么写了??

解决方案 »

  1.   

    这两行代码  (((web.Document as IHTMLDocument2).body.all as 
      IHTMLElementCollection).item('username',0) as IHTMLTextAreaElement).value:='a';   //错在这行   (((web.Document as IHTMLDocument2).body.all as 
      IHTMLElementCollection).item('password',0) as IHTMLTextAreaElement).value :='b' 放在web的onnaviagecomplete(大概是这个名字吧)事件里
      

  2.   

    参考:
    var
      Docs, ovElements: OleVariant;  try
        WebBrowser1.Navigate('mail.163.com');
        while WebBrowser1.ReadyState < READYSTATE_COMPLETE do
        Application.ProcessMessages;    Docs := WebBrowser1.OleObject.Document;
        ovElements := Docs.GetElementByName('username');
        ovElements.Value :='aaa';    Docs := WebBrowser1.OleObject.Document;
        ovElements := Docs.GetElementByName('password');
        ovElements.Value :='bbb';    Docs := WebBrowser1.OleObject.Document;
        ovElements := Docs.GetElementByID('btn1');
        ovElements.Click;
      except  end;
      

  3.   


    出来一个错误框:Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0045424F in module 'Project1.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue
      

  4.   

    错误 :
      [Error] Unit1.pas(49): Missing operator or semicolon
      [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
      

  5.   

    加入SHDocVw单元uses
      SHDocVw;
      

  6.   

      [Error] Unit1.pas(7): Identifier redeclared: 'SHDocVw'
      [Error] Unit1.pas(70): Declaration expected but 'TRY' found
      [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'加了也不行。哎
      

  7.   

     [Error] Unit1.pas(7): Identifier redeclared: 'SHDocVw' 
    那么你已经引用了SHDocVw单元,重复的可以去掉 [Error] Unit1.pas(49): Missing operator or semicolon 
    检查一下哪儿缺分号,仔细检查
      

  8.   

    哦,马虎了,这样写的,可以运行;procedure TForm1.Button4Click(Sender: TObject);
    var
      Docs, ovElements: OleVariant;
    begin
      try
        Web.Navigate('mail.163.com');
        while Web.ReadyState < READYSTATE_COMPLETE do
        Application.ProcessMessages;    Docs := Web.OleObject.Document;
        ovElements := Docs.GetElementByName('username');   //错在这行
        ovElements.Value :='aaa';    Docs := Web.OleObject.Document;
        ovElements := Docs.GetElementByName('password');
        ovElements.Value :='bbb';    Docs := Web.OleObject.Document;
        ovElements := Docs.GetElementByID('btn1');
        ovElements.Click;
      except
      end;
      end;错误框里写着:Project Project1.exe raised exception class EOleError with message 'Method 'GetElementByName' not supported by automation object'. Process stopped. Use Step or Run to continue.
      

  9.   

    这次是我测试过的,测试通过var 
      Docs, ovElements: OleVariant; 
    begin 
      try 
        Web.Navigate('mail.163.com'); 
        while Web.ReadyState  < READYSTATE_COMPLETE do 
        Application.ProcessMessages;     Docs := Web.OleObject.Document; 
        ovElements := Docs.GetElementByID('username');   //错在这行
        ovElements.Value :='aaa';    Docs := Web.OleObject.Document;
        ovElements := Docs.GetElementByID('password'); 
        ovElements.Value :='bbb';     Docs := Web.OleObject.Document; 
        ovElements := Docs.GetElementByID('btn1'); 
        ovElements.Click; 
      except 
      end;
    end;
      

  10.   

    procedure TForm1.btn2Click(Sender: TObject);
    var
      Docs, ovElements: OleVariant;
    begin
      try
        wbPage.Navigate('mail.163.com');
        while wbPage.ReadyState < READYSTATE_COMPLETE do
        Application.ProcessMessages;    Docs := wbPage.OleObject.Document;
        ovElements := Docs.GetElementsByName('username');
        ovElements.value :='aaa';    Docs := wbPage.OleObject.Document;
        ovElements := Docs.GetElementsByName('password');
        ovElements.value :='bbb';    Docs := wbPage.OleObject.Document;
        ovElements := Docs.GetElementByID('btn1');
        ovElements.Click;
      except  end;
    end;错在ovElements.value这个不行,我是用delphi7的
      

  11.   

    你这个我怎么也编译运行不了 报错。Interface not supported。