zoukankan      html  css  js  c++  java
  • 偶也来模拟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.

  • 相关阅读:
    java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
    JAVA日期处理(Timestamp)
    使用JS截取字符串函数详解
    jQuery获取select option
    JAVA获取oracle中sequences的最后一个值
    <s:iterator> 序号
    Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
    zjoi2018day1 游记
    hihocoder 后缀自动机五·重复旋律8 求循环同构串出现的次数
    hihocoder 1457 后缀自动机四·重复旋律7 求不同子串的和
  • 原文地址:https://www.cnblogs.com/spider518/p/1847534.html
Copyright © 2011-2022 走看看