我正在尝试从下拉列表中选择一个选项,第二个下拉列表应该相应地更改。 (例如,选择FL作为第一个下拉列表中的状态,第二个下拉列表将更改为佛罗里达州的所有县)
以下是网站:https://ric.novoco.com/tenant/rentincome/calculator/z1.jsp
现在,我可以在名为“State”的第一个下拉列表中成功选择选项。但名为“统计区域和名称”的第二个下拉列表不会自动更新...
这是我的代码
'start a new subroutine called LIHTC for Novogradac Rent & Income Limit
Sub lihtc()
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim btnOption As Object
Dim btnSelect As Object
Dim ElementCol As Object
Dim ElementCol1 As Object
'initiating a new instance of Internet Explorer and asigning it to objIE
Set objIE = New InternetExplorer
'make IE browser visible (False would allow IE to run in the background)
objIE.Visible = True
'navigate IE to this web page (a pretty neat search engine really)
objIE.navigate "https://ric.novoco.com/tenant/rentincome/calculator/z1.jsp"
WaitFor objIE
Set ElementCol = objIE.Document.getElementsByTagName("select")
For Each btnSelect In ElementCol
If btnSelect.Name = "state" Then
'Within the "Select" element named "Min_Qualification", group all the "Option" element in "ElementCol1"
Set ElementCol1 = btnSelect.getElementsByTagName("Option")
For Each btnOption In ElementCol1
If btnOption.Value = "FL" Then 'Select the option "FL"
btnOption.Focus
btnOption.FireEvent ("onchange")
btnOption.Selected = True
End If
Next btnOption
End If
Next btnSelect
Application.ScreenUpdating = True
WaitFor objIE
End Sub
'utility Sub: wait for page to load
Sub WaitFor(ie As Object)
While ie.readyState <> 4
DoEvents
Wend
Application.Wait Now + TimeSerial(0, 0, 3) '<<<<<< wait 3 sec
End Sub