我已经在该站点上尝试了多种变体代码,以使我的VBA可以单击网页上的按钮,但一次却无法使任何代码正常工作。一次是偶然,还是试图添加代码的下一个步骤,我无意间改变了以前发生的事情。以下是网站的源代码和我当前正在使用的代码。现在,我没有任何错误,但是,如果只是清除表单并停留在当前网页上,那么当我包含按钮单击代码时,不会加载下一页。
代码:
Public Sub TestIE()
Dim IE As Object
Dim aNodeList As Object, i As Long
Dim bNodeList As Object, p As Long
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = False
' Send the form data To URL As POST binary request
IE.Navigate "https://pe.fanniemae.com/pe/pricing/search"
' Statusbar
Application.StatusBar = "Page is loading. Please wait..."
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
IE.Visible = True
Set aNodeList = IE.document.querySelectorAll("input[type=checkbox]")
If aNodeList Is Nothing Then Exit Sub
For i = 0 To 18
aNodeList.Item(i).Checked = True
Next i
'IE.document.querySelector("button[type=submit]").Click
Set bNodeList = IE.document.querySelectorAll("button[type=submit]")
If bNodeList Is Nothing Then Exit Sub
For p = 1 To 1
bNodeList.Item(p).Click
Next p
End Sub
页面来源:
<div class="row submit">
<button id="get-price" tabindex="3" type="submit" class="cell-right-
2">Get Prices</button>
<div class="pricing-error-message"></div>
当我检查按钮上的元素时,确实出现了代码的一部分,这是我所期望的,但是由于某种原因,它清除了表单而不是加载了新页面。当我在IE中手动单击按钮时,它会按预期加载。
我认为脚本正在运行:
<script type="text/javascript">
define('pageConf', function() {
return null || JSON.parse('{\"lastPricingFactors\":
{\"priceIncrement\":\"18\",\"priceView\":\"total\",\"executionType\
":\"Mandatory\",\"levelType\":\"Product\",\"remittanceType\":\"ActualActual
\",\"products\":\"160958\",\"1036FR\",\"102422\",\"163053\",\"160639\",\"
160058\",\"155509\",\"154232\",\"143846\",\"0005FR\",\"125331\",\"102301\",
\"114921\",\"115446\",\"144854\"],\"underwrittenWithDu\":false,\"
servicingReleased\":false,\"displayMarketFrozenMessage\":false,\"windows\":
[10,30,60,90],\"requestTimeMs\":1531424470700}}')
});
</script>
答案 0 :(得分:0)
我能够利用Select Case,该案例在按钮生成的URL中插入了我想要选择的条件,而不必实际按下按钮,这似乎可以解决。感谢您看一下。