1、填充数据
a)SetAttribute("属性","值")
WebBrowser.Document.GetElementById(“ID”).SetAttribute("属性","值");
WebBrowser.Document.All[“Name”].SetAttribute("属性","值");
WebBrowser.Document.GetElementsByTagName("元素")[index].SetAttribute("属性","值");
b)InnerHtml、InnerText
WebBrowser.Document.GetElementById(“ID”).InnerHtml("值");
WebBrowser.Document.GetElementById(“ID”).InnerText("值");
2、触发事件
Focus()
InvokeMember(“click”)//执行脚本函数click、focus之类
3、光标定位到页面元素上
先引用一个Microsoft.mshtml
IHTMLWindow2 win = (IHTMLWindow2)WebBrowser.Document.Window.DomWindow;
string scriptLine = @"document.getElementById('login').focus()";
win.execScript(scriptLine, "Javascript");
{执行操作1}
通过JS来给光标定位,前提是要能找到该元素
这里同样可以用来定义其它的JS操作,改下JS语句就OK……
然后还有一个光标切换位置的:
scriptLine = "setTimeout(\"document.getElementById('pass').focus()\", 500)";
win.execScript(scriptLine, "Javascript");
我这里是用settimeout,过一段时间然后换位置,没找到其它更好,更简单的方法,目前我也就只能这么用了……
直接:
scriptLine = @"document.getElementById('loginPassword').focus()";
win.execScript(scriptLine, "Javascript");
{执行操作2}
这样两次操作都会在操作2里,不知道是个什么原因……
所以用了上面的settimeout
部分内容来自:http://blog.youkuaiyun.com/xjj800211/article/details/7814196