webbrowser页面内容填充及光标定位

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.csdn.net/xjj800211/article/details/7814196




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值