WebBrowser1如何对iframe的元素自动填表?
网页代码如下:
<iframe name="iframeLogin" id="iframeLogin" width="100%" frameborder="0" scrolling="No" src="http://www.xxxx.com/IframeLogin.asp"></iframe>请问如何自动填请呢?谢谢~
网页代码如下:
<iframe name="iframeLogin" id="iframeLogin" width="100%" frameborder="0" scrolling="No" src="http://www.xxxx.com/IframeLogin.asp"></iframe>请问如何自动填请呢?谢谢~
dim doc
set doc=me.webbrowser1.document.getElementsByTagName("IFRAME")(0).document
剩下的和一般的document访问一样了.
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这样好像不行呀.什么原因了?
vTag.value="1111"
怎么回事了?~
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"
if url = "表单所在地URL" then pDisp.document.………… (是用pDisp.document不是webbrowser.document肯定就OK了。) end if其实这个事件每当引发一次的时候就会出现一个新的URL与URL对应HTML代码(pDisp)。
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
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