Webbrowser中模擬連接點擊(非鼠標模擬)


Delphi

 

[delphi]  view plain copy
 
  1. uses  
  2.   mshtml, ActiveX;  
  3.   
  4. //初始加載網易主頁  
  5. procedure TForm1.FormCreate(Sender: TObject);  
  6. begin  
  7.   Webbrowser1.Navigate('http://www.163.com/');  
  8. end;  
  9.   
  10. procedure TForm1.Button1Click(Sender: TObject);  
  11. var  
  12. I: Integer;  
  13. Document: IHTMLDocument2;  
  14. Element: IHTMLElement;  
  15. Anchors: IHTMLElementCollection;  
  16. sLink: string;  
  17. begin  
  18.    //查找網易新聞頁面鏈接  
  19.    sLink := 'http://news.163.com/';  
  20.    Document := Webbrowser1.Document as IHTMLDocument2;  
  21.    if Assigned(Document) then  
  22.    begin  
  23.       Anchors := Document.Get_links;  
  24.       //遍歷所有鏈接  
  25.       for i := to Anchors.length - do  
  26.       begin  
  27.          Element := Anchors.item(i, varempty) as IHTMLElement;  
  28.          //找到指定鏈接  
  29.          if Assigned(Element) and (UpperCase((Element as IHTMLAnchorElement).href) = UpperCase(sLink)) then  
  30.         begin  
  31.            //執行點擊  
  32.            Element.Click;  
  33.            Break;  
  34.         end;  
  35.       end;  
  36.    end;  
  37. end;  

 

 

C#(點擊網易頁面“新聞”鏈接)

[csharp]  view plain copy
 
  1. foreach (HtmlElement element in webBrowser1.Document.Links)  
  2. {  
  3.     if (element.InnerText == "新聞")  
  4.     {  
  5.         element.InvokeMember("click");  
  6.         break;  
  7.     }  
  8. }  

http://blog.csdn.net/bdmh/article/details/6069485


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM