【发布时间】:2018-07-12 14:31:55
【问题描述】:
我正在尝试通过 VBA 检查网页上所有可用的复选框,因为名称约定似乎不是我可以选择的一种。但是我似乎无法得到任何工作。我可以登录网站并导航到我想要的网站部分,但无法跨越这个障碍。任何帮助将不胜感激。以下是网页源代码。
<li data-product-family="30yr"
data-product-amortizationTerm="30"
data-product-type="Conventional"
data-product-amortizationType="Fixed"
>
<label>
<input type="checkbox"
value="154232"
class="product-Conventional product-item"
data-authorized-remittance-types="ActualActual "
/>30-Year Fixed Rate - 110k Max Loan Amount</label>
</li>
我尝试编写(已编辑)的 VBA...我目前正在使用的代码:
Public Sub TestIE()
Dim IE As Object
Dim aNodeList As Object, i 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://"
' 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 aNodeList.Length
aNodeList.Item(i).Checked = True
Next i
End Sub
【问题讨论】:
-
您的
Exit For指示循环在第一次匹配时退出。 -
谢谢比尔,我对此有些陌生。我希望如果这是唯一的问题,它至少会检查第一个复选框,但它似乎没有这样做。运行代码时出现自动化错误和未指定的错误。
-
I cannot seem to get anything to work或but cannot cross this hurdle:这些声明并没有给我们很多工作。您收到错误消息吗?运行代码时会发生什么?另外,不要使用Click,您应该可以使用.Checked属性来设置复选框.. 除非您使用嵌入元素? -
见上面的错误。我尝试从“点击”更改为“已检查”,但无济于事。确切的错误读取:运行时错误'-2147467259(80004005)':自动化错误未指定错误
-
澄清一下,将元素设置为选中状态,您可以将其设置为:
objElement(i).Checked = True