VBA Select web element with no ID or value

rjtaylor

New Member
Joined
Jan 27, 2004
Messages
36
I am trying to grab data after I load the page sometimes there could be multiple pages of information. I have two issues first there is an option to show 10, 25, 50, or 100 items per page. I would like to start by setting the default of 10 to 100 per page. However the bigger problem is selecting the element that allows you to iterate through the pages by going to the next page
the element is:
1587087900765.png

However I cannot seem to be able to click on this element
My code to get to this page is:
VBA Code:
Sub TestSite()
Dim url As String
Dim pgcount As Integer

url = "https://www.ocpafl.org/Searches/ParcelSearch.aspx/"
'Set objIExplorer = CreateObject("InternetExplorer.Application")
Set objIExplorer = New InternetExplorerMedium
objIExplorer.Silent = True
objIExplorer.Visible = True 'for testing change to true
    
'open page
objIExplorer.navigate url
Do While objIExplorer.Busy Or Not objIExplorer.readyState = 4: DoEvents: Loop

'______________________________________________________________________________________________________________________________________
'                                                              test
                                                        WorkingPID = 262231
'                                                            end test
'---------------------------------------------------------------------------------------------------------------------------------------

objIExplorer.document.getElementById("ctl00_ctl00_ctl00_ctl00_ContentMain_ContentMain_ContentMain_ContentMain_TabContainer1_Searches_SubTabContainer1_QuickSearches_ParcelIDSearch1_ctl00_FullParcel").Value = WorkingPID

Set Btns = objIExplorer.document.getElementsByTagName("input")
    For Each b In Btns
'        MsgBox b.Value
        If b.Name = "ctl00$ctl00$ctl00$ctl00$ContentMain$ContentMain$ContentMain$ContentMain$TabContainer1$Searches$SubTabContainer1$QuickSearches$ParcelIDSearch1$ctl00$ActionButton1" Then
            b.Click
            Do While objIExplorer.Busy Or Not objIExplorer.readyState = 4: DoEvents: Loop
            Exit For
        End If
        Next
If InStr(objIExplorer.document.body, "Your search did not return any results") Then
    MsgBox "Bad Search"
    Exit Sub
End If


End Sub
I have tried multiple ways of looping through the elements but none seem to work. Any ideas?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
IE automation is a bit flaky but this code worked for me to set the 100 items per page.

Tell me when you have it tested and we can then proceed.

VBA Code:
Sub TestSite()
Dim url$, workingpid, b, pgcount%, objiexplorer, btns, cn, i%, dc
url = "https://www.ocpafl.org/Searches/ParcelSearch.aspx/"
Set objiexplorer = CreateObject("InternetExplorer.Application")
objiexplorer.Visible = True 'for testing change to true
objiexplorer.navigate url
DoEvents
Do While Not objiexplorer.readyState = 4: DoEvents: Loop
Application.Wait Now + TimeValue("0:00:03")
DoEvents
'________________________________________________________________________________________________
'                                                              test
workingpid = 262231
'                                                            end test
'------------------------------------------------------------------------------------------------
objiexplorer.Document.getElementById _
("ctl00_ctl00_ctl00_ctl00_ContentMain_ContentMain_ContentMain_ContentMain_TabContainer1_" & _
"Searches_SubTabContainer1_QuickSearches_ParcelIDSearch1_ctl00_FullParcel").Value = workingpid
Set btns = objiexplorer.Document.getElementsByTagName("input")
For Each b In btns
    If b.Name = "ctl00$ctl00$ctl00$ctl00$ContentMain$ContentMain$ContentMain$ContentMain" & _
        "$TabContainer1$Searches$SubTabContainer1$QuickSearches$ParcelIDSearch1$ctl00$ActionButton1" Then
        b.Click
        Do While objiexplorer.Busy Or Not objiexplorer.readyState = 4: DoEvents: Loop
        Exit For
    End If
Next
If InStr(objiexplorer.Document.body, "Your search did not return any results") Then
    MsgBox "Bad Search"
    Exit Sub
End If
Set cn = objiexplorer.Document.getElementsByClassName("hoverLink Selectable_Link")
Application.Wait Now + TimeValue("0:00:03")
DoEvents
MsgBox cn(0).innerText, 64, "Current value"
cn(0).TabIndex = 3
cn(0).Click
Set dc = objiexplorer.Document.getElementsByClassName("hoverLink Selectable_Selection")
MsgBox dc.Length, 64, "Number of drop down options"
dc(3).Click                                         ' desired option
End Sub
 
Upvote 0
Thanks Work that was helpful and then I worked out the rest
VBA Code:
For Each img In objiexplorer.document.images
If InStr(img.src, "/WebResource.axd?d=U-PFcFRY13Fr7yxK9RaiU3Ck7HbnQrCAKfzxMOersOPFR-f8_riUqRUnc7PQ-UOWvzR658xUg9O7uAjeQu5oTlDaau5MUUcCrKCBF4bkmkdtK0XVjIyVlj6oGXafGqX94QC110rWH7GsKJFY03snhO_3Avc1&t=637182421140000000") Then
img.Click
Exit For
End If
Next
That got the button clicked
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top