C# :webBrowser 框架网页 - 赋值 - 点击事件 - 框架网页中下拉框赋值
Posted on 2010-09-10 10:25 且行且思 阅读(6772) 评论(1) 编辑 收藏 举报net框架网页中自动插入数据 ,网上搜集了一些资料
首先对webBrowser加载网页
给一般不是框架网页中的文本框赋值
或者:this.webBrowser1.Document.All["文本框name"].SetAttribute("value", "0924");//文本框赋值根据name赋值
表单提交,也可以看成是一个点击事件
form.InvokeMember("submit");
框架网页中的文本框赋值,"frameMain"是框架的name
注:frameMain 是框架的name
框架网页中下拉框赋值
HtmlElement el = doc.GetElementById("drpXingbie");
el.SetAttribute("selectedIndex", "1");
框架网页中文本框赋值代码
tbUserid.SetAttribute("value", "k221");
HtmlElement tbPasswd = webBrowser1.Document.Window.Frames[0].Document.All["passwd"];
tbPasswd.SetAttribute("value", "33311");
HtmlDocument htmlDoc = webBrowser1.Document.Window.Frames[0].Document;
foreach (HtmlElement h in htmlDoc.All)
{
if (h.GetAttribute("type").ToString() == "submit")
{
if (h.GetAttribute("value").ToString() == "确定")
{
h.InvokeMember("click");
break;
}
}
}
获取框架内Html页面内容
1.获取frame的源文件
MessageBox.Show(webBrowser1.Document.Window.Frames["main"].Document.Body.InnerHtml);
2.获取frame的HTMLDocument接口
HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;
object j;
for (int i = 0; i < doc.parentWindow.frames.length; i++)
{
j = i;
HTMLWindow2Class frame = doc.parentWindow.frames.item(ref j) as HTMLWindow2Class;
if (frame.name == "main")
{
MessageBox.Show(frame.document.title);
}
}
3.获取frame的IHTMLDocument2接口
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.Window.Frames["main"].Document.DomDocument;
4.取得frame中被点击的连接
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
string url = webBrowser1.Document.Window.Frames["main"].Document.ActiveElement.GetAttribute("src");
}
webBrowser1.Navigate(new Uri("http://asd10000.com/"));
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.AllowWebBrowserDrop = false;
webBrowser1.WebBrowserShortcutsEnabled = false;
webBrowser1.IsWebBrowserContextMenuEnabled = false; //'屏蔽右键菜单

return;
HTMLDocument doc = webBrowser1.Document.DomDocument as HTMLDocument;
HtmlWindow window = webBrowser1.Document.Window.Frames[0];
doc = window.Document.DomDocument as HTMLDocument;
HTMLInputElementClass input = doc.all.item("username", 0) as HTMLInputElementClass;
input.value = "222an1";
input = doc.all.item("passwd", 0) as HTMLInputElementClass;
input.value = "222111";
HtmlDocument htmlDoc = webBrowser1.Document.Window.Frames[0].Document;
foreach (HtmlElement h in htmlDoc.All)
{
if (h.GetAttribute("type").ToString() == "submit")
{
if (h.GetAttribute("value").ToString() == "确定")
{
h.InvokeMember("click");
break;
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
2009-09-10 Asp.Net 与 js 的转义 (附Jquery实现的柱状图自定义对比图...)