• 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;
            }
        }
    }

  • 相关阅读:
    元类
    多态及多态性和鸭子类型
    类与对象和对应方法、封装
    面向对象与类
    内存管理与正则(re)模块
    Ajax
    Microsoft SQL Server2008安装教程
    兼容所有浏览器的关闭当前页面方法
    如何快速找到指定端口被哪个程序占用并释放该端口(解决bindException)
    MSSQL
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1954827.html
Copyright © 2020-2023  润新知