【问题标题】:How to get the updated value of an object from IE after form submission?表单提交后如何从 IE 获取对象的更新值?
【发布时间】:2018-05-26 05:58:47
【问题描述】:

我正在使用 VBA 和 IE 自动提交表单。 我可以提交表单,但是,在提交表单后,我无法获得 IE 文档中标签的最新状态 这是我用于 URL http://www.tangoloans.co.uk/brokerform/?affl_id=216的代码

网址 = "http://www.tangoloans.co.uk/brokerform/?affl_id=216" recordCount = Sheets("Data").Cells(Rows.Count, "A").End(xlUp).row

        Set appIE = New InternetExplorer
        appIE.navigate URL

        Do While appIE.readyState <> READYSTATE_COMPLETE
            Application.StatusBar = "Waiting ..."
            DoEvents
        Loop

        appIE.Visible = True
        Set Doc = appIE.document

        Doc.getElementById("title").Value = .Range("A" & row)
        Doc.getElementById("fname").Value = .Range("B" & row)
        Doc.getElementById("lname").Value = .Range("C" & row)
        Doc.getElementById("dobDay").Value = .Range("D" & row)
        Doc.getElementById("dobMonth").Value = .Range("E" & row)
        Doc.getElementById("dobYear").Value = .Range("F" & row)
        Doc.getElementById("l_amount").Value = .Range("M" & row)
        Doc.getElementById("l_terms").Value = .Range("N" & row)
        Doc.getElementById("h_phone").Value = .Range("G" & row)
        Doc.getElementById("m_phone").Value = .Range("H" & row)
        Doc.getElementById("address1").Value = .Range("J" & row)
        Doc.getElementById("town_city").Value = .Range("K" & row)
        Doc.getElementById("p_code").Value = .Range("L" & row)
        Doc.getElementById("email").Value = .Range("I" & row)

        If .Range("O" & row) = "Tenant" Then
            Doc.all("owner")(1).Click
        Else
            Doc.all("owner")(0).Click
        End If

        If .Range("P" & row) = "Tenant" Then
            Doc.all("guarantor")(1).Click
        Else
            Doc.all("guarantor")(0).Click
        End If

        Doc.getElementById("contactViaPost").Checked = True
        Doc.getElementById("contactViaEmail").Checked = True
        Doc.getElementById("contactViaPhone").Checked = True
        Doc.getElementById("agreeToTOS").Checked = True

        Doc.getElementById("submit_application").Click

        Do While appIE.readyState <> READYSTATE_COMPLETE
            Application.StatusBar = "Waiting ..."
            Application.Wait DateAdd("s", 1, Now)
        Loop

        Application.Wait DateAdd("s", 20, Now)

        Set HCollection = appIE.document.getElementsByTagName("h2")

        For Each c In HCollection
            If c.className = "vc_custom_heading" Then
                .Range("Q" & row) = c.innerText
                Exit For
            End If
        Next

然而这一行

.Range("Q" & row) = c.innerText

总是将旧文本返回给我

我尝试增加等待时间,但不是运气。有人可以帮忙吗

【问题讨论】:

    标签: vba


    【解决方案1】:

    你是cFor..Each 循环中通过HCollection 的值,这是一个包含标签名称的对象(使用getElementsByTagName 检索)来自appIE.Document em> 对象

    appIE.Document 是包含在 appIE 中的 HTML 的快照,当前是您上次“复制”HTML 时使用的行:

    Set Doc = appIE.Document
    

    再次运行该行,appIE 对象的.Document 属性的“快照”值将被“刷新”以包含InternetExplorer 对象中当前的 HTML .


    更多信息:

    【讨论】:

    • 你的意思是在Application.wait之后是这样的吗?我试过了,但它不起作用 Set Doc = appIE.document Set HCollection = Doc.getElementsByTagName("h2")
    • 如果不亲自进行实际调试,就很难进行调试。您可以发布与 vc_custom_heading 相关的 html 表单提交吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2022-11-15
    • 2012-06-12
    • 1970-01-01
    相关资源
    最近更新 更多