剛在園子里看到有博主將WebBowser控件替換為Chrome內核(),鏈接http://www.cnblogs.com/gdyblog/p/WebKitBrowser.html
於是我想既然實現了替換內核,下一步就是模擬填表單和模擬點擊等常規網頁操作了吧。於是做了一點探索。實現模擬點擊了。
代碼如下:
webBrowser1.StringByEvaluatingJavaScriptFromString("document.getElementById('su').click()");
上面這句僅能對input標簽有作用。
div或a標簽使用下面這句
webBrowser1.StringByEvaluatingJavaScriptFromString("var _elm = document.getElementById('su');var _evt = document.createEvent('MouseEvents');_evt.initEvent('click', true, true);_elm.dispatchEvent(_evt);");
C#運行頁面的JS方法可以這樣
webBrowser1.Document.InvokeScriptMethod(“Funtion1”); //Funtion1是JS的方法名稱
這個主要參考的http://blog.csdn.net/longhaoyou/article/details/46394189