webBrowser对跳转后的页面的处理
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 自动填写数据
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)//判断页面重新加载的情况
{
string dd = webBrowser1.Url.LocalPath;
if (webBrowser1.Url.LocalPath.IndexOf("WebForm1.aspx") > 0)//已经跳转到第2个页面了
{
button2_Click(sender, e);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//填充账户
webBrowser1.Document.GetElementById("TextBox1").InnerText = textBox1.Text.Trim();
//填充密码
webBrowser1.Document.GetElementById("TextBox2").InnerText = textBox2.Text.Trim();
//调用登录按钮click事件
webBrowser1.Document.GetElementById("btnClose").InvokeMember("click");
//获取提示信息
//string ts = webBrowser1.Document.GetElementById("error_div").InnerText;
//if (ts != "")
// MessageBox.Show(ts);
//while (webBrowser1.Url.LocalPath.IndexOf("WebForm1.aspx") > 0)
//{
// textBox3.Text = webBrowser1.Document.GetElementById("TextBox4").InnerText;
//}
Application.DoEvents();
}
private void button2_Click(object sender, EventArgs e)//第2个页面的处理方法
{
webBrowser1.Document.GetElementById("TextBox4").InnerText = textBox3.Text;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 自动填写数据
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)//判断页面重新加载的情况
{
string dd = webBrowser1.Url.LocalPath;
if (webBrowser1.Url.LocalPath.IndexOf("WebForm1.aspx") > 0)//已经跳转到第2个页面了
{
button2_Click(sender, e);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//填充账户
webBrowser1.Document.GetElementById("TextBox1").InnerText = textBox1.Text.Trim();
//填充密码
webBrowser1.Document.GetElementById("TextBox2").InnerText = textBox2.Text.Trim();
//调用登录按钮click事件
webBrowser1.Document.GetElementById("btnClose").InvokeMember("click");
//获取提示信息
//string ts = webBrowser1.Document.GetElementById("error_div").InnerText;
//if (ts != "")
// MessageBox.Show(ts);
//while (webBrowser1.Url.LocalPath.IndexOf("WebForm1.aspx") > 0)
//{
// textBox3.Text = webBrowser1.Document.GetElementById("TextBox4").InnerText;
//}
Application.DoEvents();
}
private void button2_Click(object sender, EventArgs e)//第2个页面的处理方法
{
webBrowser1.Document.GetElementById("TextBox4").InnerText = textBox3.Text;
}
}
}