本帖最后由 lovewangya 于 2010-12-17 08:25:46 编辑

解决方案 »

  1.   

    inputObj.Value改成inputObj.innerText
      

  2.   

    何必这么辛苦,看我的!Option ExplicitPrivate Sub Command1_Click()
      WebBrowser1.Navigate "C:\Documents and Settings\Administrator\桌面\index.htm"
    End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    On Error GoTo hErr     If (pDisp Is WebBrowser1.Object) Then '下载完毕
              '填写内容
              WebBrowser1.Document.All("textfield1").Value = "4227739"
              WebBrowser1.Document.All("textfield2").Value = "*******"
         End If
    hErr:
    '出错了
    End Sub
      

  3.   

    路径搞错了!按楼主的!
    Option ExplicitPrivate Sub Command1_Click()
         WebBrowser1.Navigate "http://127.0.0.1/index.html"
    End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    On Error GoTo hErr     If (pDisp Is WebBrowser1.Object) Then '下载完毕
              '填写内容
              WebBrowser1.Document.All("textfield1").Value = "4227739"
              WebBrowser1.Document.All("textfield2").Value = "*******"
         End If
    hErr:
    '出错了
    End Sub
      

  4.   

    代码修改如下,已通过:Private Sub Command1_Click()
        WebBrowser1.Navigate "c:\index.html"
    End SubPublic Function getElementByClassName(doc As HTMLDocument, tagName As String, className As String)
        Dim objElem As IHTMLElement
        Dim objElems As IHTMLElementCollection
        
        Set objElems = doc.getElementsByTagName(tagName)
        For Each objElem In objElems
            If objElem.className = className Then
                Set getElementByClassName = objElem
                Exit Function
                Exit For
            End If
        Next
        getElementByClassName = "错误"
    End Function
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, url As Variant)
        Dim doc As HTMLDocument
        Dim inputObj As HTMLInputElement    If Me.WebBrowser1.Object = pDisp Then
            Set doc = WebBrowser1.Document
            Set inputObj = getElementByClassName(doc, "input", "qq")
            inputObj.Value = 123
        End If
    End Sub
      

  5.   

    Public Function getClassName(doc, tagName, className) As Object
       Dim doc_1 As Object, i As Object
       Set doc_1 = doc.getElementsByTagName(tagName)
       For Each i In doc_1
          If i.className = className Then
             Set getClassName = i
             Exit Function
          End If
       Next
       Set getClassName = Nothing
    End FunctionPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
       Dim doc As Object, inputObj As Object
       If WebBrowser1.Document.ReadyState = "complete" Then
          Set doc = WebBrowser1.Document
          Set inputObj = getClassName(doc, "input", "qq")
          'MsgBox (inputObj)
          If (inputObj Is Nothing) Then
             MsgBox "出现错误!", 48, "错误"
          Else
             inputObj.Value = 123
          End If
       End If
    End Sub