【NET】WebBrowser执行脚本以及一般操作代码
public class WebBrowserAssistant
{
System.Windows.Forms.WebBrowser wb;
public WebBrowserAssistant(System.Windows.Forms.WebBrowser wb) {
this.wb = wb;
}
public bool SetElementValue(string id,string value) {
this.wb.Document.GetElementById(id).SetAttribute("value", value);
return true;
} public object InvokeScript(string scriptName) {
return this.wb.Document.InvokeScript(scriptName);
}
public object InvokeScript(string scriptName,object[] ps)
{
return this.wb.Document.InvokeScript(scriptName, ps);
}
public void GetFocus(string id)
{
this.wb.Document.GetElementById(id).Focus();
}
public void GetBlur(string id)
{
this.wb.Document.GetElementById(id).RemoveFocus();
}
public string GetInputIDByName(string name)
{
return GetInputIDByName(name, name);
} public void ClickElement(string id) {
this.wb.Document.GetElementById(id).InvokeMember("click");
}
public string GetInputIDByName(string name,string id)
{
System.Windows.Forms.HtmlElementCollection es = this.wb.Document.GetElementsByTagName("input");
if (es != null && es.Count > ) {
System.Collections.IEnumerator ie = es.GetEnumerator();
System.Windows.Forms.HtmlElement e;
while (ie.MoveNext()) {
e = (System.Windows.Forms.HtmlElement)ie.Current;
if (e.Name.Equals(name))
{
if (string.IsNullOrEmpty(e.Id))
{
e.Id = id;
}
return e.Id;
}
}
}
return null;
} public List<string> GetEletemtByName(string name)
{
System.Windows.Forms.HtmlElementCollection es = this.wb.Document.GetElementsByTagName("input");
if (es != null && es.Count > )
{
List<string> result = new List<string>();
System.Collections.IEnumerator ie = es.GetEnumerator();
System.Windows.Forms.HtmlElement e;
while (ie.MoveNext())
{
e = (System.Windows.Forms.HtmlElement)ie.Current;
if (e.GetAttribute("type").Equals("checkbox") && e.Name.Equals(name) && e.GetAttribute("checked").Equals("True"))
{
result.Add(e.GetAttribute("value"));
}
}
return result;
}
return null;
}
public string ExeScript(string scriptBlock) {
return ExeScript(scriptBlock, "tempEletemtTagNameAndID");
}
public string ExeScript(string scriptBlock,string tempEletemtTagNameAndID) {
System.Windows.Forms.HtmlElement ele;
if (this.wb.Document.GetElementById(tempEletemtTagNameAndID) == null) {
ele = this.wb.Document.CreateElement(tempEletemtTagNameAndID);
ele.Id = tempEletemtTagNameAndID;
this.wb.Document.Body.AppendChild(ele);
}
ele = this.wb.Document.CreateElement("script");
ele.SetAttribute("type", "text/javascript"); ele.SetAttribute("text", string.Format("$j(\"#{0}\").val({1})", tempEletemtTagNameAndID, scriptBlock));
this.wb.Document.Body.AppendChild(ele); return this.wb.Document.GetElementById(tempEletemtTagNameAndID).GetAttribute("value");
} }
调用
MessageBox.Show(new Huawei.PortableComputer.Util.WebBrowserAssistant(this.wbTaskList).ExeScript("$j('.listContentTable td :checkbox:checked:first').parent().next().next().next().text()"));
【NET】WebBrowser执行脚本以及一般操作代码的更多相关文章
- WebBrowser执行脚本和调用外部方法
控制WebBrowser实际上就是控制IE,最简单的方法就是执行javascript或vbscript,省去了接口的转换.如何执行脚本?以前我一直用mshtml中IHTMLWindow2接口的exec ...
- WebBrowser执行脚本
ExecuteJavaScript(WebBrowser:TWebBrowser; Code: string):Variant;var //发送脚本Document:IHTMLDocument2;Wi ...
- winform中WebBrowser控件执行脚本
在实际应用中我们可能需要WebBrowser控件主动执行我们需要的脚本,执行脚本现在有两种方法. 1.WebBrowser控件加载脚本,简单方便,适用于简短的脚本,无法执行复杂操作. webBrows ...
- winform下利用webBrowser执行javascript
目前很多网站为了防止恶意提交表单信息,大多都采用了加密的方式对提交信息进行处理,加密处理后通过POST提交给服务器验证,这种操作一般都是用Javascipt进行加密,若是我们想要正确提交表单到网站,就 ...
- Tsung脚本中使用动态参数(一)---直接在脚本里编写Erlang代码
杀死一个程序猿,只要改三次需求.同理,杀死一个接口自动化测试人员,只要改三次接口数据处理方式.我目前的状态,改了一次接口数据处理方式,有一种胸闷的感觉. 因为改需求,所以,要改脚本.T_T.所以,才有 ...
- Android手机上,利用bat脚本模拟用户操作
………… 那么你就可以来看看这篇帖子了. 言归正传 利用bat脚本模拟用户操作,需要用到两点: ①就是adb命令了,adb命令可以用来模拟用户在手机上的操作 ②bat语言,就是批处理语言,主要用来进行 ...
- JSch远程执行脚本
JSch远程执行脚本 2017-02-24 在自动化测试的时候,需要远程操控服务器做一些操作,比如切日.起服务器.执行某些脚本.如何实现? 我们可以利用JSch,远程执行脚本.JSch是Java Se ...
- PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)
源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...
- ExtJS 4.1 TabPanel动态加载页面并执行脚本【转】
ExtJS 4.1 TabPanel动态加载页面并执行脚本 按照官方示例,可以动态加载页面,可是脚本不执行,于是查SDK.google,发现scripts需要设置为true,于是设置该属性,整个代码如 ...
随机推荐
- mysql_SQL_按照日统计微博数
主要备忘: DATE_FORMAT 函数 1:微博对比图(按日统计) SELECT DATE_FORMAT(tw.article_publish_time, '%Y-%m-%d'),count(pag ...
- [ 流行的网络框架 ] AFN & ASI
1.AFN & ASI(早已经停止更新,但现在许多公司也在使用.) AFNetWorking地址:https://github.com/AFNetworking/AFNetworking AS ...
- MySQL检查连接的最大数量和改变的最大连接数
版权声明:本文博主原创文章.博客,未经同意不得转载.
- 2014牡丹江区域赛H(特里)ZOJ3826
Hierarchical Notation Time Limit: 2 Seconds Memory Limit: 131072 KB In Marjar University, stude ...
- Cocos2d-x 3.0 编译出错 解决 error: expected ';' at end of member declaration
近期把项目移植到cocos2d-x 3.0,在整Android编译环境的时候,出现一大堆的编译出错,都是类似"error: expected ';' at end of member dec ...
- c语言下多线程
原文:c语言下多线程 [问题]创建了10个线程,10个线程公用一个线程体,创建如下: int t1=0,t2=1,t3=2,t4=3,t5=4,t6=5,t7=6,t8=7,t9=8,t10=9; i ...
- awk的实施例
1.使用split功能 name.url内容: 上海 http://trip.elong.com/shanghai/jingdian elong destination 云南 http ...
- Aspose.Words:如何添加另一个WORD文档中的Node对象
原文:Aspose.Words:如何添加另一个WORD文档中的Node对象 首先看一段代码,这段代码意图从docSource中获取第一个表格,并插入docTarget的末尾: , true); doc ...
- 客户端Webview重定向
今天在客户端的网页中写了句alert的代码,发现执行了两次,后来发现网页的地址写的是http://192.168.14.72/app 客户端Webview加载网页,对于不完全路径会重定向到完全路径,导 ...
- OpenSUSE 13.2安装Texlive2014+Texmaker+Lyx
(1)首先下载安装Texlive2014 地址:http://mirrors.ustc.edu.cn/CTAN/systems/texlive/Images/ 或直接下载: wget http://m ...