• 偶也来模拟Delphi登陆网页


    这篇文章也不算是原创,毕竟参考了某位大牛代码,好了废话不说了直接代码了:

    登录前:

    登陆后:

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OleCtrls, SHDocVw, UIWebBrowser, MSHtml, StdCtrls, WinSkinData,
      bsSkinData, BusinessSkinForm;

    type
      TForm1 = class(TForm)
        Label1: TLabel;
        Edit1: TEdit;
        Label2: TLabel;
        Edit2: TEdit;
        Button2: TButton;
        UIWebBrowser1: TUIWebBrowser;
        SkinData1: TSkinData;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      //UiWebBrowser1.Navigate('http://localhost/User/Login.asp');
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    var
      Doc: IHTMLDocument2;
      userinputelement, pwdinputelement: ihtmlinputelement;
    begin
      doc := UiWebBrowser1.document as ihtmldocument2;
      userinputelement := (doc.all.item('name', 0) as ihtmlinputelement);
      userinputelement.value := Trim(Edit1.Text);
      pwdinputelement := (doc.all.item('password', 0) as ihtmlinputelement);
      pwdinputelement.value := Trim(Edit2.Text);
    //  下面三种都可以,自己测试
      //按按钮名称来点击
      //wb1.OleObject.document.all.item('btnLogin').click;
      //按钮钮ID来点击
      // wb1.OleObject.document.getElementByID('btnLogin').click ;
      //按第几个按钮来点击
      //UiWebBrowser1.OleObject.document.getElementsByTagName('Input').item(4).click;
      UIWebBrowser1.OleObject.Document.all.item('submit').Click;
      Label1.Visible := False;
      Edit1.Visible := False;
      Label2.Visible := False;
      Edit2.Visible := False;
      Button2.Visible := False;
    end;


    procedure TForm1.FormCreate(Sender: TObject);
    begin
      UiWebBrowser1.Navigate('http://localhost/User/Login.asp');
    end;

    end.

  • 相关阅读:
    杭电 1548 A strange lift(广搜)
    JAVA数组的定义及用法
    WPF之Binding深入探讨
    FBReaderJ源代码编译配置
    【剑指offer】合并两有序单链表
    对HGE游戏引擎的一次封装
    WAV文件格式分析
    Ubuntu9.04更新源
    内核及内核模块
    java实现第七届蓝桥杯愤怒小鸟
  • 原文地址:https://www.cnblogs.com/spider518/p/1847534.html
Copyright © 2020-2023  润新知