click to a link in iframe

前端 未结 1 1445
生来不讨喜
生来不讨喜 2021-01-29 07:12

i search for a method to click to a link in an iframe in VBA code

what i still done:

Set IEApp = GetObject(\"new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}\"         


        
1条回答
  •  清酒与你
    2021-01-29 07:36

    Try using a CSS selector to target the element within the iframe.

    If you think it is a timing problem you can

    1) loop while target element is nothing i.e. not set; with timeout to avoid potential for infinite loop

    Dim t As Date, ele As Object, waitTime As Long
    t = Timer
    waitTime = 10 '<== secs
    Do
        DoEvents
        On Error Resume Next
        Set ele = IEDocument.frames("IFRAME").document.querySelector("a[href=javascript:choose('Objektnummer, Referenznummer')]")
        On Error GoTo 0
        If Timer - t = waitTime Then Exit Do     '<==To avoid infinite loop
    Loop While ele Is Nothing
    Call IEDocument.iframe.execScript("Choose('Objektnummer,Referenznummer')", "JavaScript")
    

    2) Set an explicit wait

    Application.Wait Now + TimeSerial(0,0,5) '<== adjust 5 which is number of seconds
    Call IEDocument.iframe.execScript("Choose('Objektnummer,Referenznummer')", "JavaScript")
    

    0 讨论(0)
提交回复
热议问题