1.给页面注入Javascript并执行
'脚本内容为:javascript:document.Survey_Form.Action.value = 'SurveyOverSubmit';Survey_Form_Submit();
Dim ele As HtmlElement
ele = Web.Document.CreateElement("script")
ele.SetAttribute("type", "text/javascript")
ele.SetAttribute("text", "javascript:document.Survey_Form.Action.value = 'SurveyOverSubmit';Survey_Form_Submit();")
Web.Document.Body.AppendChild(ele)
2.运行页面中javascript函数
webBrowser1.Document.InvokeScript(“someInPageJavaFunction”,
null)
3.关闭脚本错误弹出对话框
webbrowser.ScriptErrorsSuppressed=true
4.触发button按钮click事件
HtmlElement btn = webBrowser1.document.getElementByIdx_x(“aBtn”);
if(btn !=null)
btn.InvokeMember(“click”);
5.读取,设置javacript变量
需要引用mshtml
Dim vDocument As IHTMLDocument2 = TryCast(Web.Document.DomDocument, IHTMLDocument2)
Dim vWindow As IHTMLWindow2 = DirectCast(vDocument.parentWindow, IHTMLWindow2)
Dim vWindowType As Type = vWindow.[GetType]()
Dim testText As Object = vWindowType.InvokeMember("tmp", BindingFlags.GetProperty, Nothing, vWindow, New Object() {})
' 读取
'vWindowType.InvokeMember("tmp", BindingFlags.SetProperty, Nothing, vWindow, New Object() {"30000"})
' 设置
'vWindowType.InvokeMember("setTimeout", BindingFlags.InvokeMethod, Nothing, vWindow, New Object() {"Timer()", 30000})
' 执行方法
6.获取HTML元素属性值
MessageBox.Show(Web.Document.GetElementById("verifyCode").GetAttribute("value"))
7.滚动到页面底部
Web.Document.Window.ScrollTo(0, Web.Document.Body.ScrollRectangle.Height)
8.HTML文本框获得焦点
Web.Document.GetElementById("verifyCode").Focus()
9.单选框同名时选择
Web.Document.All.GetElementsByName("option_7_" & x.ToString).Item(r.Next(2, 4) - 1)
10.触发SUBMIT按钮
Web.Document.Forms("Survey_Form").All("SurveyOverSubmit").InvokeMember("click")
Web.Document.GetElementById("verifyCode").SetAttribute("value", "fdasfda")