2016-04-23 11 views
0

私は、ウェブサイトにアクセスし、郵便番号を入力し、郵便番号を追加し、次のページに行くためにボタンを押してプログラムを取得しようとしています。私のコードは以下の通りです。VBA特定のボタンをクリック

私はこのページに固執しており、「プロパティ」タブをクリックして次のページに移動するプログラムを取得できません。このボタンをクリックしてもらえますか?

私は.GetElementsbyID("").clickを試みたが、それが動作するようには思えない...

私が押したいボタンの周りのWebページのコード:

<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

変数をeleに設定する必要がある場合があります。 – Glib

答えて

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 
関連する問題