[控件使用]webBrowser中操作网页元素全攻略
来源:互联网 发布:百度网盘软件 编辑:程序博客网 时间:2024/05/17 09:47
1、获取非input控件的值:
webBrowser1.Document.All["控件ID"].InnerText;
或webBrowser1.Document.GetElementById("控件ID").InnerText;
或webBrowser1.Document.GetElementById("控件ID").GetAttribute("value");
2、获取input控件的值:
webBrowser1.Document.All["控件ID"].GetAttribute("value");;
或webBrowser1.Document.GetElementById("控件ID").GetAttribute("value");
3、给输入框赋值:
webBrowser1.Document.GetElementById("控件ID").SetAttribute("value", "控件值");
4、CheckBox选中:
webBrowser1.Document.GetElementById("控件ID").SetAttribute("Checked", "true");
5、根据已知有ID的元素操作没有ID的元素:
HtmlElement btnDelete = webBrowser1.Document.GetElementById(passengerId).Parent.Parent.Parent.Parent.FirstChild.FirstChild.Children[1].FirstChild.FirstChild;
根据Parent,FirstChild,Children[1]数组,多少层级的元素都能找到。
6、获取Div或其他元素的样式:
webBrowser1.Document.GetElementById("addDiv").Style;
7、直接执行页面中的脚本函数,带动态参数或不带参数都行:
Object[] objArray = new Object[1];
objArray[0] = (Object)this.labFlightNumber.Text;
webBrowser1.Document.InvokeScript("ticketbook", objArray);
webBrowser1.Document.InvokeScript("return false");
8、自动点击、自动提交:
HtmlElement btnAdd = doc.GetElementById("addDiv").FirstChild;
btnAdd.InvokeMember("Click");
9、自动赋值,然后点击提交按钮的时候如果出现脚本错误或一直加载的问题,一般都是点击事件执行过快,这时需要借助Timer控件延迟执行提交按钮事件:
this.timer1.Enabled = true;
this.timer1.Interval = 1000 * 2;
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
ClickBtn.InvokeMember("Click");//执行按扭操作
}
10、屏蔽脚本错误:
将WebBrowser控件ScriptErrorsSuppressed设置为True即可
11、自动点击弹出提示框:
参考:http://www.cnblogs.com/qqflying/archive/2012/07/25/2608038.html
12、获取网页中的Iframe,并设置Iframe的src
HtmlDocument docFrame = webBrowser1.Document.Window.Frames["mainFrame"].Document;
或
HtmlDocument docFrame = webBrowser1.Document.All.Frames["mainFrame"].Document;
docFrame.All["mainFrame"].SetAttribute("src", "http://www.baidu.com/");
13、网页中存在Iframe的时候webBrowser1.Url和webBrowser1_DocumentCompleted中的e.Url不一样,前者是主框架的Url,后者是当前活动框口的Url。
14、让控件聚焦
this.webBrowser1.Select();
this.webBrowser1.Focus();
doc.All["TPL_password_1"].Focus();
- [控件使用]webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- webBrowser中操作网页元素全攻略
- PB调用WEBBROWSER控件进行网页操作
- webBrowser操作网页找不到节点元素使用输入键盘SendKeys.send
- VC,webbrowser控件中关闭网页窗口
- C#中使用WebBrowser控件
- 【C#】[网络]WebBrowser网页操作(提取元素,自动填表)
- Delphi使用VB控件全攻略
- Delphi使用VB控件全攻略
- Delphi使用VB控件全攻略
- Delphi使用VB控件全攻略
- 《代码整洁之道》--函数
- Linux: 脚本中配置开发中常用的变量
- Android 4.0.4模拟器安装完全教程(图文)
- 我的php学习笔记(十二)php生产HTML文件原理
- 黑马程序员----JAVA----常用类----
- [控件使用]webBrowser中操作网页元素全攻略
- 新东方六级5-12
- MFC 利用控制台输出调试信息(转)
- adb 启动activity
- JNI生成头文件
- 2013-01-30千里眼项目
- [控件使用]WebBrowser 的使用方法
- Shell脚本编程——几个内部命令
- mysql启动错误的处理