1、根据元素ID获取元素的值。

比如要获取<img class="" id="regimg" src="/register/checkregcode.html?1287068791" width="80" height="22">这个标签里的src属性的值:

mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)webBrowser1.Document; mshtml.IHTMLElement img = (mshtml.IHTMLElement)doc2.all.item("regimg", 0);

string imgUrl = (string)img.getAttribute("src");

2、填写表单,并确定

mshtml.IHTMLElement loginname = (mshtml.IHTMLElement)doc2.all.item("loginname", 0);     mshtml.IHTMLElement loginPW = (mshtml.IHTMLElement)doc2.all.item("password", 0);     mshtml.IHTMLElement loginBT = (mshtml.IHTMLElement)doc2.all.item("formsubmit", 0);     mshtml.IHTMLElement loginYZ = (mshtml.IHTMLElement)doc2.all.item("regcode", 0);     loginname.setAttribute("value", tbLoginName.Text);
loginPW.setAttribute("value", tbLoginPassWord.Password); 
loginYZ.setAttribute("value", tbYZ.Text);    
loginBT.click();

3、获取源码

textBox1.Text = doc2.body.innerHTML;

4、执行JS

mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc2.parentWindow;
win.execScript("changeRegImg()", "javascript");//使用JS

5、禁止JS,WPF下目前发现唯一适用的一种方法:

public void HideScriptErrors(WebBrowser wb, bool Hide)   
{
    FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);

if (fiComWebBrowser == null) return;

object objComWebBrowser = fiComWebBrowser.GetValue(wb);

if (objComWebBrowser == null) return;

objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null,objComWebBrowser, new object[] { Hide });

}

void webBrowser1_Navigated(object sender, NavigationEventArgs e)   
{

HideScriptErrors(webBrowser1,  true);

}

最新文章

  1. Android APK如何签名
  2. 【WP8.1开发】认识后台任务
  3. 如果觉得配置文件没有错,但web-dev-server总是报错,可以在hosts文件里加一行127.0.0.1 localhost
  4. 【转】解决编译安装NGINX时make报错
  5. 内存中 OLTP - 常见的工作负荷模式和迁移注意事项(二)
  6. Thread源码分析
  7. iphone获取当前运行进程列表
  8. javascript回车完美实现tab切换功能
  9. mkpasswd
  10. 判断div是否隐藏
  11. ruby2.0(rails)以后版本的debug
  12. Hibernate实体映射配置(XML)简单三步完美配置
  13. 安装Java Cer证书
  14. python之decode、encode及codecs模块
  15. 防止SQL注入的6个要点
  16. PostgresSQL使用Copy命令能大大提高数据导入速度
  17. LeetCode: Valid Sudoku 解题报告
  18. dp之最长递增、公共子序列总结
  19. javascript 类型 内存 对象
  20. ES博客链接

热门文章

  1. graphviz使用
  2. MyBatis---简单增删改查的带事物的例子
  3. 1082: [SCOI2005]栅栏
  4. C# 委托、Lambda表达式和事件——学习总结
  5. 《Cracking the Coding Interview》——第11章:排序和搜索——题目6
  6. Python 爬取网页中JavaScript动态添加的内容(一)
  7. JMeter学习笔记(四) HTTP Cookies 管理器
  8. Pytest框架介绍
  9. Linux利用OneinStack搭建环境
  10. REMIX与LOCALHOST相连