//登录
private void toolStripButton1_Click(object sender, EventArgs e)
{ //ie.ExecuteScript("alert('ok!');");
}
//安装脚本
private void toolStripButton2_Click(object sender, EventArgs e)
{ //ie.InstallScript("function add(num1,num2){return num1+num2;}");
//ie.ExecuteScript("alert(add(1,2));");
}
//调用js
private void toolStripButton3_Click(object sender, EventArgs e)
{ //ie.InstallScript("function showInfo(name,age){document.write('姓名:'+name+'年龄:'+age.toString());}");
//ie.InvokeScript("showInfo",new object[]{"小红",10});
}
//JQuery模拟搜索百度
private void toolStripButton4_Click(object sender, EventArgs e)
{
// if (string.IsNullOrEmpty(this.txtKeyword.Text))
// return; // ie.Navigate("http://www.baidu.com/");
// //等待页面载入后,才执行
// ie.IEFlow.Wait(new UrlCondition("wait","http://www.baidu.com/",StringCompareMode.StartWith));
// ie.InstallJQuery(JQuery.CodeMin);
// ie.ExecuteJQuery(JQuery.Create("'#kw'").Val("'"+ this.txtKeyword.Text.Trim()+"'"));
// ie.ExecuteJQuery(JQuery.Create("'#su'").Click());
} private void btnStraRe_Click(object sender, EventArgs e)
{
// this.ie.IERecord.InstallRecord();
// this.ie.IERecord.BeginRecord();
} private void btnEndRe_Click(object sender, EventArgs e)
{
//this.ie.IERecord.EndRecord();
} private void btnRe_Click(object sender, EventArgs e)
{
//this.ie.IERecord.BeginReplay();
} private void btnSave_Click(object sender, EventArgs e)
{
//this.ie.IERecord.SaveAction(@"record.txt");
} private void btnLoad_Click(object sender, EventArgs e)
{
//this.ie.IERecord.LoadAction(@"record.txt");
}
自动登录 干部在线培训
private void btnLogin_Click(object sender, EventArgs e)
{
//ie.IEFlow.Wait(new UrlCondition("wait", "http://passport.chinahrt.com/login.do", StringCompareMode.StartWith));
//ie.InstallJQuery(JQuery.CodeMin);
//ie.ExecuteJQuery(JQuery.Create("'#loginName'").Val("'" + this.txtName.Text.Trim() + "'"));
//ie.ExecuteJQuery(JQuery.Create("'#loginPwd'").Val("'" + this.txtPwd.Text.Trim() + "'").toMD5());
//ie.ExecuteJQuery(JQuery.Create("'#loginBtn'").Click());
//以上采用JQuery方法,不能实现toMD5方法。解放方法1:实现toMD5方法;方法2:调本原来的checkSubmit();方法3:用webBrowser给文本框赋值,再调用checkSubmit方法
//只能用方法3了。因为用ie,给loginPwd赋值后,再执行submit,变量没有变成MD5.
HtmlElement name = wbBrowser.Document.All["loginName"];
HtmlElement pwd = wbBrowser.Document.All["loginPwd"];
HtmlElement sub = wbBrowser.Document.All["loginBtn"]; name.SetAttribute("value",this.txtName.Text.Trim());
pwd.SetAttribute("value", this.txtPwd.Text.Trim());
sub.InvokeMember("click"); }