不要使用webbrowser等控件在程序中打开网页的方法,
网页是在ie浏览器中的。直接操作ie浏览器中网页的输入框,获取和修改其内容。
模拟键盘鼠标 ie接口都可以,有例子么?

解决方案 »

  1.   

    如果有id,根据id找 var
       o:OleVariant;
      i:integer;
      Doc:IHTMLDocument2;
      userinputelement,pwdinputelement,ValidateElement:ihtmlinputelement;
    begin
      Doc:=WebBrowser1.document as ihtmldocument2;
      if doc=nil then exit;
      userinputelement:=(doc.all.item('payFeeOnlineInfo.productNO',0) as ihtmlinputelement);
      userinputelement.value:=ed_ltcode.Text;
      userinputelement:=(doc.all.item('payFeeOnlineInfo.productNOAgain',0) as ihtmlinputelement);
      userinputelement.value:=ed_ltcode.Text;
      userinputelement:=(doc.all.item('payFeeOnlineInfo.checkCode',0) as ihtmlinputelement);
      userinputelement.value:=ed_ltyz.Text;
      userinputelement:=(doc.all.item('payFeeOnlineInfo.payFee',0) as ihtmlinputelement);
      userinputelement.value:=ed_ltprice.Text;  o:=doc.all.item('submit0',0);
      state := 101;
      o.click;
      //o:=doc.all.item('payButton',0);
      //o.click;end;
      

  2.   

    ie应该没有提供这种接口。思路:
    1. 利用GetActiveWindow取得当前输入框的的handle
    2. 给输入框发送wm_gettext取得输入框的值或发送wm_settext设置输入框的值未测试过。你可以试试
      

  3.   

    楼上这种方法,首先是通过WebBrowser1打开网页了。我要的是直接操作ie的。通过ie接口或其他方法。实际上可以做一个自动填表的ie面板,通过HtmlDocument := IE.Document as IHTMLDocument2 可以获取和操作ie页面元素。但我想做个独立的程序。就是不知道怎么得到ie的Document。另外ie页面元素也没有句柄。
      

  4.   

    to truexf:IE是独立管理页面元素的,所以利用GetActiveWindow取得当前输入框的的handle是不可能的。
      

  5.   

    从网上找到了一个vc的说法,有delphi的么:
       
      1、通过IE句柄得到IHTMLDocument2接口   
      http://blog.csdn.net/lion_wing/archive/2006/05/26/756105.aspx   
      2、通过IHTMLDocumnet2得到网页源代码   
      http://blog.csdn.net/lion_wing/archive/2006/06/02/769742.aspx
      

  6.   

    你自己翻译下就行了,他用的基本都是Windows系统函数。
      

  7.   

    Private Sub ShellExecuteIE(Mode As Integer)
    On Error Resume Next
        Dim Titles As String
        Dim IEList As New SHDocVw.ShellWindows
        Dim Doc
        Dim i As Integer
        Dim j As Integer
        Dim LocalNames As String
        Dim Name As String, Password As String, Security As String
        'If FormType = 1 Then
            'Name = "username"
            'Password = "password"
            'Security = "ekey"
       ' Else
            Name = "idInput"
            Password = "pwdInput"
            'Security = "username5"
        'End If
        'If FormType = 1 Then
            'Titles = "纵横天下官方网站 - 盛大网络"
        'Else
            Titles = "126网易免费邮--你的专业电子邮局"
        'End If
        '遍历当前浏览器窗口
        j = IEList.Count
        For i = 0 To j - 1
            '找到需要的IE窗口
            LocalNames = Left(IEList.Item(i).LocationName, Len(Trim(Titles)))
            If LocalNames = Trim(Titles) Then
                '获得浏览器文档对象,填写表单
                Set Doc = IEList.Item(i).Document
                Doc.body.All("" & Name & "").Value = Trim(Text1.Text)    '用户名
                Doc.body.All("" & Password & "").Value = Trim(Text2.Text)  '密码
                'Doc.body.All("" & Security & "").Value = Trim(Text3.Text)   '密保
                If Mode = 1 Then
                    
                Else
                    '直接提交网页
                    'If FormType = 1 Then
                        'Doc.Forms("login").Submit
                    'Else
                        Doc.Forms("loginBtn").Submit
                    'End If
                End If
                Command3.Enabled = True
                Command4.Enabled = True
                Exit Sub
            End If
        Next
        MsgBox "登录入口未加载完毕,请稍候再试!", vbSystemModal + vbOKOnly + vbExclamation, "Error"
        Command3.Enabled = True
        Command4.Enabled = True
    End Sub找了个vb的,用126测试,可以赋值,但是提交不执行!!!
    另外我自己需要赋值的网站(包含框架),连赋值都不行。