我正在尝试获取一个访问网站的程序,输入邮政编码,添加邮政编码,然后按一个按钮进入下一页。我的代码如下。
现在我被困在这个页面上,无法让程序单击“属性”选项卡并转到我想要查看的下一页。点击此按钮可以获得任何帮助吗?
我试过了.GetElementsbyID("").click
,但这似乎不起作用......
我要按的按钮周围的网页代码:
<span class="geographymap-span-tab" id="tab_PROPERTY_PAGE" onclick="showSearchTypeSection('PROPERTY_PAGE','PROPERTY')"><img id="PROPERTY_PAGE_IMG" src="/list/images/PROPERTY_PAGE_2.gif" alt="property" width="80" height="29" border="0" onmouseover="MM_swapImage('PROPERTY_PAGE')" onmouseout="MM_swapImgRestore('PROPERTY_PAGE')"></span>
到目前为止我的代码如下:
Sub TestProgram()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.Navigate "http://www.listsource.com/build.marketing.list"
' Statusbar
Application.StatusBar = "www.listsource.com is loading. Thanks and Gig 'em..."
' Application.StatusBar = False
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Focus on the drop down menu
IE.document.getElementByID("locator").Focus
'Select zip code which happens to be the 19th item
IE.document.getElementByID("locator").selectedIndex = 19
'Get to the right page based on that selection
IE.document.getElementByID("locator").FireEvent ("onchange")
'input zipcode
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Application.StatusBar = "Search form submission. Please wait..."
Set objCollection = IE.document.getElementsByTagName("textarea")
i = 0
While i < objCollection.Length
If objCollection(i).Name = "zipTextArea" Then
' Set text for search
objCollection(i).Value = "75225"
Else
If objCollection(i).Type = "button" And _
objCollection(i).Name = "addZip" Then
' "Search" button is found
Set objElement = objCollection(i)
End If
End If
i = i + 1
Wend
' pull all elements that are buttons
Set objInputs = IE.document.getElementsByTagName("button")
'click button
For Each ele In objInputs
If ele.Name Like "addZip" Then
ele.Click
End If
Next
' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
' FIND OUT total # of SFR in each given zip code
' Click on "Property" button
End Sub
我可以添加什么来点击属性选项卡?
答案 0 :(得分:0)
或者您可以检查表单(searchform)以查找名为“addzip”的所有元素,然后单击它遇到的第一个元素。
'(Dim frm as object)
'(Dim btnAdd as object)
Set frm = IE.document.forms("searchform")
Set btnAdd = frm.all("addzip")(0)
btnAdd.click