如何在表单提交后从IE获取对象的更新值?

时间:2018-05-26 05:58:47

标签: vba

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

的代码

网址=“http://www.tangoloans.co.uk/brokerform/?affl_id=216”     recordCount =表格(“数据”)。单元格(Rows.Count,“A”)。结束(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”&amp; row)= c.innerText

总是给我留下旧文本

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

1 个答案:

答案 0 :(得分:0)

c循环中For..Each的值HCollectiongetElementsByTagName是一个对象,包含来自的标记名称(使用appIE.Document检索) appIE.Document 对象

appIESet Doc = appIE.Document 中包含的HTML的快照,是您上次“复制”HTML的最新动态,您正在使用该行:

.Document

再次运行该行,appIE对象的InternetExplorer属性的“snapshot”值将被“刷新”,以包含当前中的HTML {{1}}对象。

更多信息: