One of the users have helped me to know the topic of Locating HTML elements with CSS selectors : querySelector() method is much more easier than getElementsBy() https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll#obtaining_a_list_of_matches...In code below, I want to access elements of all with innerText View Listing. For that purpose I wrote code below where querySelectorAll takes the parent div with class module(as an array, or collection, list call how you want) successfully. But after I was not able to go on element by element neither with querySelect() nor within for loop;
Public Sub newEditionQry()
Const URL As String = "https://cooperatordirectory.com/search_results?location_value=Florida&adm_lvl_1_sn=FL&stateSearchLN=Florida&country_sn=US&location_type=administrative_area_level_1&stateSearch=FL&swlat=24.396308&nelat=31.000968&swlng=-87.634896&nelng=-79.974306&lat=27.6648274&lng=-81.5157535&faddress=Florida%2C+USA&place_id=ChIJvypWkWV2wYgR0E7HW9MTLvc"
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
With ie
.Visible = True
.navigate URL
Do While .readyState <> READYSTATE_COMPLETE Or .Busy: DoEvents: Loop
Set a = .document.querySelectorAll(".module")
For Each element In a
Debug.Print a.querySelector("a.btn").innerText ' err line
Next element
End With
End Sub
What will I do if I will be able to catch elements with viewListing Texts. I will manipulate each of them ( if you give a look the website, you see they are dozens of them) by method click.
<div class="module nomargin text-center">
<a class="btn btn-success btn-block" href="/pro/20220324090906">View Listing</a>
<div class="clearfix bpad"></div>
<a class="btn btn-primary btn-block" href="/pro/20220324090906/connect">Send Message</a>
</div>