WebBrowser1如何对iframe的元素自动填表?
网页代码如下:
<iframe name="iframeLogin" id="iframeLogin" width="100%" frameborder="0" scrolling="No" src="http://www.xxxx.com/IframeLogin.asp"></iframe>请问如何自动填请呢?谢谢~

解决方案 »

  1.   

    如果只有一个iframe,可以如此进行
    dim doc
    set doc=me.webbrowser1.document.getElementsByTagName("IFRAME")(0).document
    剩下的和一般的document访问一样了.
      

  2.   

    Private Sub Command2_Click()
    Dim i As Integer
    Dim vDoc, vTag As Variant
    Set vDoc = Me.WebBrowser1.Document.getElementsByTagName("IFRAME")(1).Document
     For i = 0 To vDoc.All.length - 1 '检测所有标签
                If UCase(vDoc.All(i).tagName) = "INPUT" Then  '找到input标签
                    Set vTag = vDoc.All(i)
                    If vTag.Name = "ptname" Then
                        vTag.Value = "1111" '这个是输入到用户名中得值
                    End If
                    If vTag.Name = "ptpwd" Then
                        vTag.Value = "2222"  '这个是输入到密码框中的值
                    End If
        End If
        Next i
    End Sub这样好像不行呀.什么原因了?
      

  3.   

    set vTag=vDoc.getElementsByName("ptname")(0)
    vTag.value="1111"
      

  4.   

    对象变量或WITH块变量未设置.
    怎么回事了?~
      

  5.   

    哪个变量未定义?完整的代码如下:
    dim vDoc,vTag
    set vDoc=me.webbrowser1.document.getElementsByTagName("IFRAME")(1).document '第二个iframe
    set vTag=vDoc.getElementsByName("ptname")(0) '必须保证ptname是text类型的input
    vTag.value="1111"
      

  6.   

    自己动手试验下么其实这些都是些参数的修改自己试验一下就能知道的我以前用webbrower的时候连问的地方都没有
      

  7.   

    好像IFRAME的src如果不是同一个域的话,是访问不了的
      

  8.   

    webbrower控件的documentplement事件中有一个URl和一个pDisp参数。打开一个网页documentplement事件执行至少一次,没当有一个FRAME时候肯定会多执行一次。找到表单所在地FRAME的URL,然后在documentplement事件中写如下代码:
        if url = "表单所在地URL" then        pDisp.document.………… (是用pDisp.document不是webbrowser.document肯定就OK了。)    end if其实这个事件每当引发一次的时候就会出现一个新的URL与URL对应HTML代码(pDisp)。
      

  9.   

    哦,如果想知道哪个URL是你想要地表单所以的URL,不妨先在documentplement事件中把所有的URL全部打印出来,然后用IE挨个网址打开看。估计应该可以。
      

  10.   

    好了可以结贴啦,记得给我加分。Private Sub Form_Load()
    WebBrowser1.Navigate "(父地址)http://www.xxxx.com/"
    End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If URL = "(父地址)http://www.xxxx.com/" Then
    WebBrowser1.Document.parentWindow.frames("iframeLogin").Document.All("ptname").Value = "1111"
    WebBrowser1.Document.parentWindow.frames("iframeLogin").Document.All("ptpwd").Value = "2222"
    WebBrowser1.Document.parentWindow.frames("loginframe").Document.All("imglogin").Click
    End If
    End Sub
      

  11.   

    Private Sub Form_Load() 
    WebBrowser1.Navigate "(父地址)http://www.xxxx.com/" 
    End Sub Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) 
    If URL = "(父地址)http://www.xxxx.com/" Then 
    WebBrowser1.Document.parentWindow.frames("iframeLogin").Document.All("ptname").Value = "1111" 
    WebBrowser1.Document.parentWindow.frames("iframeLogin").Document.All("ptpwd").Value = "2222" 
    WebBrowser1.Document.parentWindow.frames("iframeLogin").Document.All("imglogin").Click 
    End If 
    End Sub