开发者

Changing data in child iFrame issue - can't obtain a DOM object

For some reason I'm trying to parse this website: http://www.vblandrecords.com/index.aspx. I am currently trying to click Document type tab and then change From date value.

I supposed I could have done it with the following code, in VBA:

Option Explicit
Public WithEvents ieObj As InternetExplorer

Public Sub Launch()

    Set ieObj = CreateObject("InternetExplorer.Application")
    ieObj.Visible = True
    ieObj.navigate ("http://www.vblandrecords.com/index.aspx")

    While ieObj.readyState <> READYSTATE_COMPLETE

    Wend

    Dim TmpDOMObj, Frame As Object

    Set TmpDOMObj = ieObj.document.getElementById("tbMaintd3")

    TmpDOMObj.Click

    Set Frame = ieObj.document.getElementB开发者_如何学运维yId("tbMain_frame3")
    Set TmpDOMObj = Frame.contentWindow.document.getElementById("txtStart")

    TmpDOMObj.Value = "10/1/2010"    

End Sub

But, I got a run-time error 91 - object variable not set.

I've done some research and it appeared that tree structure under tbMain_frame3 is formed up only after I click tbMaind3 tab, and I see it in MSIE developer tools, but I don't see it in my script.

I thought it was related to iFrame security issues I've read about, but staying on first tab and processing tbMain_frame0 works entirely fine.

Can anyone give me a hint about what's going on and how to handle this page?

Thanks.


It may not be the best idea, but you could wait for the error to go away:

Dim test
On Error Resume Next

Do While True
    test = Frame.contentWindow.Document.getElementById("txtStart").Value
    If Err.Number = 0 Then
        Exit Do
    ElseIf Err.Number > 0 And Err.Number <> 91 Then
        Exit Sub
    End If

    Err.Clear
Loop
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜