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执行脚本以及一般操作代码的更多相关文章

  1. WebBrowser执行脚本和调用外部方法

    控制WebBrowser实际上就是控制IE,最简单的方法就是执行javascript或vbscript,省去了接口的转换.如何执行脚本?以前我一直用mshtml中IHTMLWindow2接口的exec ...

  2. WebBrowser执行脚本

    ExecuteJavaScript(WebBrowser:TWebBrowser; Code: string):Variant;var //发送脚本Document:IHTMLDocument2;Wi ...

  3. winform中WebBrowser控件执行脚本

    在实际应用中我们可能需要WebBrowser控件主动执行我们需要的脚本,执行脚本现在有两种方法. 1.WebBrowser控件加载脚本,简单方便,适用于简短的脚本,无法执行复杂操作. webBrows ...

  4. winform下利用webBrowser执行javascript

    目前很多网站为了防止恶意提交表单信息,大多都采用了加密的方式对提交信息进行处理,加密处理后通过POST提交给服务器验证,这种操作一般都是用Javascipt进行加密,若是我们想要正确提交表单到网站,就 ...

  5. Tsung脚本中使用动态参数(一)---直接在脚本里编写Erlang代码

    杀死一个程序猿,只要改三次需求.同理,杀死一个接口自动化测试人员,只要改三次接口数据处理方式.我目前的状态,改了一次接口数据处理方式,有一种胸闷的感觉. 因为改需求,所以,要改脚本.T_T.所以,才有 ...

  6. Android手机上,利用bat脚本模拟用户操作

    ………… 那么你就可以来看看这篇帖子了. 言归正传 利用bat脚本模拟用户操作,需要用到两点: ①就是adb命令了,adb命令可以用来模拟用户在手机上的操作 ②bat语言,就是批处理语言,主要用来进行 ...

  7. JSch远程执行脚本

    JSch远程执行脚本 2017-02-24 在自动化测试的时候,需要远程操控服务器做一些操作,比如切日.起服务器.执行某些脚本.如何实现? 我们可以利用JSch,远程执行脚本.JSch是Java Se ...

  8. PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)

    源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...

  9. ExtJS 4.1 TabPanel动态加载页面并执行脚本【转】

    ExtJS 4.1 TabPanel动态加载页面并执行脚本 按照官方示例,可以动态加载页面,可是脚本不执行,于是查SDK.google,发现scripts需要设置为true,于是设置该属性,整个代码如 ...

随机推荐

  1. Android游戏开发研究与主角在地图滚动

     让人感动的地图过程平滑滚动         玩过rpg朋友应该都知道RPG的游戏地图一般都比較大 今天我和大家分享一下在RPG游戏中怎样来处理超出手机屏幕大小的游戏地图. 如图所看到的为程序效果 ...

  2. XP 多国语言包

    http://download.microsoft.com/download/f/6/4/f648c363-6975-470c-8202-ac5aea706109/WindowsXP-KB835935 ...

  3. Gaea是支持跨平台具有高并发、高性能、高可靠性,并提供异步、多协议、事件驱动的中间层服务框架

    Gaea是支持跨平台具有高并发.高性能.高可靠性,并提供异步.多协议.事件驱动的中间层服务框架 Gaea:58同城开源的中间层服务框架 https://github.com/58code/Gaea 中 ...

  4. NodeJS,我对“高、高、非”的一些看法

    ·众所周知 NodeJS三大神器"事件驱动,V8,回调函数". ·事件驱动,故名思议:等快递和收快递区别.NodeJS将原先大牛们掌握的神神秘秘的EPOLL走向大众化,这点是最大的 ...

  5. HTTP 错误500.19 -Internal Server Error

    原文:HTTP 错误500.19 -Internal Server Error HTTP 错误500.19 -Internal Server Error 错误代码 0x80070021 评论1 字号: ...

  6. 多个Storyboard切换

    - (void)showStoryboard { // 实例化MainStoryboard UIStoryboard *storyboard = [UIStoryboard storyboardWit ...

  7. 谈论quick-cocos2d-x和cocos2d-x lua了解差异

    之前说,我把这个两个词区别.经过太长时间.当然,反击的麻烦.quick-cocos2d-x它提到quick,cocos2d-x lua姑且称为本地lua对. 我认为,首先与这两个小的朋友接触会跟着或多 ...

  8. jQuery邮箱验证正则表达式验证邮箱合法

    if($.trim(email)==''||$.trim(email)=='邮    箱:'||$.trim(email)==null){ alert('邮箱不能为空!'); return false ...

  9. 手机web下拉加载

    //需要 zepto.js支持 var page=0;//当前页 var pages=1;//总页数 var ajax=!1;//是否加载中 Zepto(function($){ $(window). ...

  10. SQL点滴12—SQL Server备份还原数据库中的小把戏

    原文:SQL点滴12-SQL Server备份还原数据库中的小把戏 备份数据库时出现一个不太了解的错误 ,错误信息“is formatted to support  1 media families, ...