惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
V
Visual Studio Blog
有赞技术团队
有赞技术团队
U
Unit 42
D
Docker
小众软件
小众软件
F
Full Disclosure
I
Intezer
Scott Helme
Scott Helme
P
Privacy International News Feed
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
B
Blog
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
宝玉的分享
宝玉的分享
S
Security Affairs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
Schneier on Security
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Threat Research - Cisco Blogs
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Heimdal Security Blog
N
Netflix TechBlog - Medium
H
Hacker News: Front Page
P
Proofpoint News Feed
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
S
Schneier on Security

博客园 - flashicp

一个购物分享网站核心源码分析 ECSHOP读写分离配置与改造(转载) - flashicp 多年没有管理的技术博客了,即日起开始管理起技术博客 Apache里的 MPM 调优比较详细 zend framework多模块多布局配置 c# office不同版本下中使用Excel 目录下的文件 - flashicp - 博客园 中秋 国庆 最近在忙项目,好久不来 转 :如何提高自己的编程水平 衣物去污指南 转 洗衣小窍门集锦 牙膏的妙用 转 家居小窍门 (二) 转 家居小窍门 (一) 转 --有些事情需要注意 WinForm的App.config 保存我的操作日志 关于sql server表名 和字段的一点操作
c# WebBrowser网页操作-元素获取_事件操作
flashicp · 2012-05-27 · via 博客园 - flashicp

usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms;// namespaceWebBrowser网页操作 { publicclassElement { //根据Name获取元素 publicHtmlElement GetElement_Name(WebBrowser wb,stringName) { HtmlElement e = wb.Document.All[Name]; returne; } //根据Id获取元素 publicHtmlElement GetElement_Id(WebBrowser wb, stringid) { HtmlElement e = wb.Document.GetElementById(id); returne; } //根据Index获取元素 publicHtmlElement GetElement_Index(WebBrowser wb,intindex) { HtmlElement e = wb.Document.All[index]; returne; } //获取form表单名name,返回表单 publicHtmlElement GetElement_Form(WebBrowser wb,stringform_name) { HtmlElement e = wb.Document.Forms[form_name]; returne; } //设置元素value属性的值 publicvoidWrite_value(HtmlElement e,stringvalue) { e.SetAttribute("value", value); } //执行元素的方法,如:click,submit(需Form表单名)等 publicvoidBtn_click(HtmlElement e,strings) { e.InvokeMember(s); } } } 这是调用这个类的窗体代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; namespaceWebBrowser网页操作 { publicpartialclassForm1 : Form { Element el = newElement(); publicForm1() { InitializeComponent(); } privatevoidForm1_Load(objectsender, EventArgs e) { webBrowser1.Navigate(Application.StartupPath + @"\Test.html"); } privatevoidbutton1_Click(objectsender, EventArgs e) { el.Write_value(el.GetElement_Name(webBrowser1,"username"),"isaced"); } privatevoidbutton2_Click(objectsender, EventArgs e) { el.Write_value(el.GetElement_Id(webBrowser1, "password"), "123456"); } privatevoidbutton3_Click(objectsender, EventArgs e) { el.Btn_click(el.GetElement_Id(webBrowser1,"button"),"click");//方法用的按钮click } privatevoidbutton4_Click(objectsender, EventArgs e) { el.Btn_click(el.GetElement_Form(webBrowser1, "form1"), "submit");//先获取表单,再调用表单的submit方法 } } }

posted on 2012-05-27 22:52  flashicp  阅读(4856)  评论()    收藏  举报