您的位置:首页 > 编程语言 > C#

C# 通过webBrowser 框架网页

2009-08-18 11:26 344 查看
最近一段时间因为公司老板的要求:要求我对其他人开发的net框架网页中自动插入数据,开始的时候我不清楚,后来到网上搜集了一些资料
首先对webBrowser加载网页

this.webBrowser1.Url = new System.Uri("url地址", System.UriKind.Absolute);
给一般不是框架网页中的文本框赋值

webBrowser1.Document.GetElementById("文本框ID").InnerText = "weiling";//文本框赋值根据ID赋值
或者:this.webBrowser1.Document.All["文本框name"].SetAttribute("value", "0924");//文本框赋值根据name赋值
表单提交,也可以看成是一个点击事件

HtmlElement form = webBrowser1.Document.GetElementById("formID");//提交表单
form.InvokeMember("submit");
框架网页中的文本框赋值,"frameMain"是框架的name

webBrowser1.Document.Window.Frames["frameMain"].Document.GetElementById("txtXingming").InnerText = "521656";//框架赋值
注:frameMain 是框架的name
框架网页中下拉框赋值

HtmlDocument doc = webBrowser1.Document.Window.Frames["frameMain"].Document;//框架下下拉框赋值
HtmlElement el = doc.GetElementById("drpXingbie");
el.SetAttribute("selectedIndex", "1");


come on~~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: