Webbrowser模擬百度一下子點擊事件


Webbrowser模擬百度一下點擊事件
新建一個form,有一個button和一個webbrowser控件。
然后webbrowser一開始加載的就是百度主頁。
然后在文本框里輸入點東西,如何做到點擊button就相當於點擊點擊webbrowser中的“百度一下”按鈕?

 


------解決方案--------------------
refer:

    private void Form1_Load(object sender, EventArgs e)  
    {  
        this.webBrowser1.Url = new Uri("http://www.baidu.com");//指定url地址為百度首頁  
    }  
      
    private void button1_Click(object sender, EventArgs e)  
    {  
        HtmlElement searchWords = webBrowser1.Document.All["kw"];//獲取百度搜索的文本框  
        HtmlElement searchButton = webBrowser1.Document.All["su"];//獲取百度搜索的按鈕  
        searchWords.SetAttribute("value", "guwei4037");//給百度搜索的文本框賦值  
        searchButton.InvokeMember("click");//調用百度搜索按鈕的點擊事件  


免責聲明!

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



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