How to print each element Class in a different cell in a sheet

Js Smith

Board Regular
Joined
Jul 24, 2020
Messages
51
Office Version
  1. 2010
Platform
  1. Windows
Hi all!

I'm writing vba using selenium and uses the chromedriver.

I know this will print each dropdown's label value from a webpage in a different cell in Sheet1 and it works:

VBA Code:
Dim i As Long
i = 1
Set rvar2s = bot.FindElementsByXPath("//*[starts-with(@id,'pneumo')]")
For Each rvar2 In rvar2s
i = i + 1
Sheets("Sheet1").Cells(i, 2).Value = rvar2.Text
Next rvar2

How do I print each dropdown's element Class from a webpage in a different cell in a sheet?

Sometimes the beginning of an element is the same and the end is different. I can't figure out how to set values to a series of dropdowns where part of the element class changes. Right now I can only manipulate the first dropdown by using an xpath starts-with

So attempting to pivot, if I could know the exact class for each dropdown then I could target each dropdown and set their value. I don't want to manually inspect each dropdown on the page to get the class. If I have to do it manually, it defeats the purpose of automating.

If you have anyone has better ideas, I'm all ears. Thanks!!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi Js, can you maybe share a bit more code/which site you're trying to automate? I'll gladly have a go at it (did quite some VBA-based scraping myself), but this example is rather minimalistic. If you're not okay sharing it here, do send me a DM.
 
Upvote 0
Hi Js, can you maybe share a bit more code/which site you're trying to automate? I'll gladly have a go at it (did quite some VBA-based scraping myself), but this example is rather minimalistic. If you're not okay sharing it here, do send me a DM.
Hi Rijinsent!

The variable 10-digit codes are the problem and judging from what I've seen on this site this sort of thing will occur again as I progress in script writing.
I can't give you access to the site but here's a few takes on the code:

Using Chrome to inspect:
HTML:
<select id="page_06_relation_1000174402_to_1000174429" name="relation_1000174402_to_1000174429" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined"><option value="default">Relation</option><option value="19">Child (son or daughter)</option><option value="31">Court-Appointed Guardian</option><option value="53">Domestic partner</option><option value="05">Grandchild (grandson or granddaughter)</option><option value="04">Grandparent (grandfather or grandmother)</option><option value="13">Mother-in-law or Father-in-law</option><option value="03">Parent (father or mother)</option><option value="14">Sibling (brother or sister)</option><option value="11">Son-in-law or Daughter-in-law</option><option value="01">Spouse</option><option value="17">Stepchild (stepson or stepdaughter)</option><option value="16">Stepparent (stepfather or stepmother)</option><option value="15">Ward</option><option value="G9">Other</option></select>

The Xpath of the same:
HTML:
//*[@id="page_06_relation_1000174402_to_1000174429"]

This is how the Selenium Chrome addon sees it on a recording, selecting "Spouse" from the list ::
Rich (BB code):
    "id": "82d2b6c3-c22d-4107-a8c2-ca1674ae7f00",
      "comment": "",
      "command": "click",
      "target": "id=page_06_relation_1000174402_to_1000174429",
      "targets": [
        ["id=page_06_relation_1000174402_to_1000174429", "id"],
        ["name=relation_1000174402_to_1000174429", "name"],
        ["css=#page_06_relation_1000174402_to_1000174429", "css:finder"],
        ["xpath=//select[@id='page_06_relation_1000174402_to_1000174429']", "xpath:attributes"],
        ["xpath=//div[@id='fhRelationship']/div/form/div[2]/select", "xpath:idRelative"],
        ["xpath=//select", "xpath:position"]
      ],
      "value": ""
    }, {
      "id": "ca159432-cfb6-4454-845f-4e3b2f96609b",
      "comment": "",
      "command": "select",
      "target": "id=page_06_relation_1000174402_to_1000174429",
      "targets": [],
      "value": "label=Spouse"
    }, {
 
Upvote 0
Hi Rijinsent!

The variable 10-digit codes are the problem and judging from what I've seen on this site this sort of thing will occur again as I progress in script writing.
I can't give you access to the site but here's a few takes on the code:

Using Chrome to inspect:
HTML:
<select id="page_06_relation_1000174402_to_1000174429" name="relation_1000174402_to_1000174429" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined"><option value="default">Relation</option><option value="19">Child (son or daughter)</option><option value="31">Court-Appointed Guardian</option><option value="53">Domestic partner</option><option value="05">Grandchild (grandson or granddaughter)</option><option value="04">Grandparent (grandfather or grandmother)</option><option value="13">Mother-in-law or Father-in-law</option><option value="03">Parent (father or mother)</option><option value="14">Sibling (brother or sister)</option><option value="11">Son-in-law or Daughter-in-law</option><option value="01">Spouse</option><option value="17">Stepchild (stepson or stepdaughter)</option><option value="16">Stepparent (stepfather or stepmother)</option><option value="15">Ward</option><option value="G9">Other</option></select>

The Xpath of the same:
HTML:
//*[@id="page_06_relation_1000174402_to_1000174429"]

This is how the Selenium Chrome addon sees it on a recording, selecting "Spouse" from the list ::
Rich (BB code):
    "id": "82d2b6c3-c22d-4107-a8c2-ca1674ae7f00",
      "comment": "",
      "command": "click",
      "target": "id=page_06_relation_1000174402_to_1000174429",
      "targets": [
        ["id=page_06_relation_1000174402_to_1000174429", "id"],
        ["name=relation_1000174402_to_1000174429", "name"],
        ["css=#page_06_relation_1000174402_to_1000174429", "css:finder"],
        ["xpath=//select[@id='page_06_relation_1000174402_to_1000174429']", "xpath:attributes"],
        ["xpath=//div[@id='fhRelationship']/div/form/div[2]/select", "xpath:idRelative"],
        ["xpath=//select", "xpath:position"]
      ],
      "value": ""
    }, {
      "id": "ca159432-cfb6-4454-845f-4e3b2f96609b",
      "comment": "",
      "command": "select",
      "target": "id=page_06_relation_1000174402_to_1000174429",
      "targets": [],
      "value": "label=Spouse"
    }, {
My edit timed out. Somebody came by my desk for a question.



I'm working around the current problem by iterating the dropdown's list of values, using the Xpath test and setting the values via a spreadsheet.

Thanks for taking a look!
Hi Rijinsent!

The variable 10-digit codes are the problem and judging from what I've seen on this site this sort of thing will occur again as I progress in script writing.
I can't give you access to the site but here's a few takes on the code:

Using Chrome to inspect:
HTML:
<select id="page_06_relation_1000174402_to_1000174429" name="relation_1000174402_to_1000174429" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined"><option value="default">Relation</option><option value="19">Child (son or daughter)</option><option value="31">Court-Appointed Guardian</option><option value="53">Domestic partner</option><option value="05">Grandchild (grandson or granddaughter)</option><option value="04">Grandparent (grandfather or grandmother)</option><option value="13">Mother-in-law or Father-in-law</option><option value="03">Parent (father or mother)</option><option value="14">Sibling (brother or sister)</option><option value="11">Son-in-law or Daughter-in-law</option><option value="01">Spouse</option><option value="17">Stepchild (stepson or stepdaughter)</option><option value="16">Stepparent (stepfather or stepmother)</option><option value="15">Ward</option><option value="G9">Other</option></select>

The Xpath of the same:
HTML:
//*[@id="page_06_relation_1000174402_to_1000174429"]

This is how the Selenium Chrome addon sees it on a recording, selecting "Spouse" from the list ::
Rich (BB code):
    "id": "82d2b6c3-c22d-4107-a8c2-ca1674ae7f00",
      "comment": "",
      "command": "click",
      "target": "id=page_06_relation_1000174402_to_1000174429",
      "targets": [
        ["id=page_06_relation_1000174402_to_1000174429", "id"],
        ["name=relation_1000174402_to_1000174429", "name"],
        ["css=#page_06_relation_1000174402_to_1000174429", "css:finder"],
        ["xpath=//select[@id='page_06_relation_1000174402_to_1000174429']", "xpath:attributes"],
        ["xpath=//div[@id='fhRelationship']/div/form/div[2]/select", "xpath:idRelative"],
        ["xpath=//select", "xpath:position"]
      ],
      "value": ""
    }, {
      "id": "ca159432-cfb6-4454-845f-4e3b2f96609b",
      "comment": "",
      "command": "select",
      "target": "id=page_06_relation_1000174402_to_1000174429",
      "targets": [],
      "value": "label=Spouse"
    }, {
My edit timed out. Somebody came by my desk for a question. :sneaky:

I'm working around the current problem by iterating the dropdown's list of values, using the Xpath test and setting the values via a spreadsheet.

Thanks for taking a look!
 
Upvote 0
Hi Js,

mmm, that doesn't make my answering of your question much easier, a good practice would be to provide a "minimum reproducable example", but hey, I'll try without :-). So I'm coming at this question from a slightly different angle, as I'm not using Selenium, but some default components.
In your situation I would try to see if the site itself makes some API call, so you don't have to go through the forms & pages, but can basically call the backend directly. You can try to see if there are any API calls (normally replying JSON) with the "inspect"->"network" screen. That generally speeds up the scraping process considerably.
Anyhow, what I did below is to pull in a website where I found some dropdowns, listing them, their ID, their CLASS and the options. The pulling in of the website is a bit elaborate, as I'm using the same code to pull in JSON and to create e.g. POST messages.

Hope this helps!


Basic VBA GET/POST call:
VBA Code:
Function WebRequestURL(strUrl As String, strMethod As String, Optional objHeaders As Dictionary, Optional strPostMsg As String) As String

' Instantiate a WinHttpRequest object and open it
ErrResp = "{""error_nr"":ERR_NR,""error_txt"":""ERR_TXT""}"
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.SetTimeouts 5000, 5000, 5000, 120000
'Resolve, Connect, Send and Receive in ms

If strMethod = "GET" Then
    On Error Resume Next
    objHTTP.Open "GET", strUrl
    If Not objHeaders Is Nothing Then
        For Each Key In objHeaders.Keys()
            'e.g. objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
            objHTTP.setRequestHeader Key, objHeaders(Key)
        Next Key
    Else
        'No headers
    End If
    
    objHTTP.send
    If Err.Number = 0 Then
        If objHTTP.Status = "200" Then
            objHTTP.WaitForResponse
            WebRequestURL = objHTTP.responseText
        Else
            WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText)
        End If
    Else
        'Unknown error, probably no internet connection, answer in JSON
        WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description)
    End If
    On Error GoTo 0
ElseIf strMethod = "POST" Then
    On Error Resume Next
    objHTTP.Open "POST", strUrl
    If Not objHeaders Is Nothing Then
        For Each Key In objHeaders.Keys()
            'e.g. objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
            objHTTP.setRequestHeader Key, objHeaders(Key)
        Next Key
    Else
        'No headers
    End If

    If strPostMsg = "" Then
        objHTTP.send
    Else
        objHTTP.send (strPostMsg)
    End If

    If Err.Number = 0 Then
        If objHTTP.Status = "200" Then
            objHTTP.WaitForResponse
            WebRequestURL = objHTTP.responseText
        Else
            WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText)
            Debug.Print objHTTP.responseText
        End If
    Else
        'Unknown error, probably no internet connection, answer in JSON
        WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description)
    End If
    On Error GoTo 0

Else
    WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", 27), "ERR_TXT", "invalid method for WebRequestURL")
End If
Set objHTTP = Nothing

End Function

Specific to loop through all SELECT elements (dropdowns) on a page and get their class, id and options, do make sure you have:
-a sheet named ONE
-in the VBA-editor references (under extra->references) to Microsoft HTML object library and
-Microsoft Scripting Runtime

VBA Code:
Sub GetSelectsAndOptions()

Dim doc As HTMLDocument
Dim Url As String

Set doc = New HTMLDocument

NewLines = ""
Url = "https://getbootstrap.com/docs/4.0/components/forms/"
Dim headerDict As New Dictionary
headerDict.Add "User-Agent", "Mozilla/5.0"
'headerDict.Add "X-Requested-With", "XMLHttpRequest"

ResTxt = WebRequestURL(Url, "GET", headerDict)
doc.body.innerHTML = ResTxt

Rw = 2
Set Ws = Worksheets("ONE")
Ws.Range("A1").Value = "HTML"
Ws.Range("B1").Value = "ID"
Ws.Range("C1").Value = "CLASS"

Ws.Range("E1").Value = "OPTION 1 (etc)"

'Set TblsTd = doc.getElementsByClassName("plusIconTd")
Set TdSel = doc.getElementsByTagName("select")

For Each s In TdSel
    'Debug.Print s.outerHTML
    Ws.Cells(Rw, 1).Value = s.outerHTML
    
    For Each a In s.Attributes
        If a.Name = "id" Then
            'Debug.Print "ID: " & a.Value
            Ws.Cells(Rw, 2).Value = a.Value
        End If
        
        If a.Name = "class" Then
            'Debug.Print "CLASS: " & a.Value
            Ws.Cells(Rw, 3).Value = a.Value
        End If
    Next a
    
    n = 0
    For Each op In s.Options
        'Debug.Print op.outerHTML, "OPTION: " & op.Value
        Ws.Cells(Rw, 5 + n).Value = op.outerHTML
        n = n + 1
    Next op
    Rw = Rw + 1
Next s

End Sub
 
Upvote 0
Hi Js,

mmm, that doesn't make my answering of your question much easier, a good practice would be to provide a "minimum reproducable example", but hey, I'll try without :). So I'm coming at this question from a slightly different angle, as I'm not using Selenium, but some default components.
In your situation I would try to see if the site itself makes some API call, so you don't have to go through the forms & pages, but can basically call the backend directly. You can try to see if there are any API calls (normally replying JSON) with the "inspect"->"network" screen. That generally speeds up the scraping process considerably.
Anyhow, what I did below is to pull in a website where I found some dropdowns, listing them, their ID, their CLASS and the options. The pulling in of the website is a bit elaborate, as I'm using the same code to pull in JSON and to create e.g. POST messages.

Hope this helps!


Basic VBA GET/POST call:
VBA Code:
Function WebRequestURL(strUrl As String, strMethod As String, Optional objHeaders As Dictionary, Optional strPostMsg As String) As String

' Instantiate a WinHttpRequest object and open it
ErrResp = "{""error_nr"":ERR_NR,""error_txt"":""ERR_TXT""}"
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.SetTimeouts 5000, 5000, 5000, 120000
'Resolve, Connect, Send and Receive in ms

If strMethod = "GET" Then
    On Error Resume Next
    objHTTP.Open "GET", strUrl
    If Not objHeaders Is Nothing Then
        For Each Key In objHeaders.Keys()
            'e.g. objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
            objHTTP.setRequestHeader Key, objHeaders(Key)
        Next Key
    Else
        'No headers
    End If
   
    objHTTP.send
    If Err.Number = 0 Then
        If objHTTP.Status = "200" Then
            objHTTP.WaitForResponse
            WebRequestURL = objHTTP.responseText
        Else
            WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText)
        End If
    Else
        'Unknown error, probably no internet connection, answer in JSON
        WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description)
    End If
    On Error GoTo 0
ElseIf strMethod = "POST" Then
    On Error Resume Next
    objHTTP.Open "POST", strUrl
    If Not objHeaders Is Nothing Then
        For Each Key In objHeaders.Keys()
            'e.g. objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
            objHTTP.setRequestHeader Key, objHeaders(Key)
        Next Key
    Else
        'No headers
    End If

    If strPostMsg = "" Then
        objHTTP.send
    Else
        objHTTP.send (strPostMsg)
    End If

    If Err.Number = 0 Then
        If objHTTP.Status = "200" Then
            objHTTP.WaitForResponse
            WebRequestURL = objHTTP.responseText
        Else
            WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText)
            Debug.Print objHTTP.responseText
        End If
    Else
        'Unknown error, probably no internet connection, answer in JSON
        WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description)
    End If
    On Error GoTo 0

Else
    WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", 27), "ERR_TXT", "invalid method for WebRequestURL")
End If
Set objHTTP = Nothing

End Function

Specific to loop through all SELECT elements (dropdowns) on a page and get their class, id and options, do make sure you have:
-a sheet named ONE
-in the VBA-editor references (under extra->references) to Microsoft HTML object library and
-Microsoft Scripting Runtime

VBA Code:
Sub GetSelectsAndOptions()

Dim doc As HTMLDocument
Dim Url As String

Set doc = New HTMLDocument

NewLines = ""
Url = "https://getbootstrap.com/docs/4.0/components/forms/"
Dim headerDict As New Dictionary
headerDict.Add "User-Agent", "Mozilla/5.0"
'headerDict.Add "X-Requested-With", "XMLHttpRequest"

ResTxt = WebRequestURL(Url, "GET", headerDict)
doc.body.innerHTML = ResTxt

Rw = 2
Set Ws = Worksheets("ONE")
Ws.Range("A1").Value = "HTML"
Ws.Range("B1").Value = "ID"
Ws.Range("C1").Value = "CLASS"

Ws.Range("E1").Value = "OPTION 1 (etc)"

'Set TblsTd = doc.getElementsByClassName("plusIconTd")
Set TdSel = doc.getElementsByTagName("select")

For Each s In TdSel
    'Debug.Print s.outerHTML
    Ws.Cells(Rw, 1).Value = s.outerHTML
   
    For Each a In s.Attributes
        If a.Name = "id" Then
            'Debug.Print "ID: " & a.Value
            Ws.Cells(Rw, 2).Value = a.Value
        End If
       
        If a.Name = "class" Then
            'Debug.Print "CLASS: " & a.Value
            Ws.Cells(Rw, 3).Value = a.Value
        End If
    Next a
   
    n = 0
    For Each op In s.Options
        'Debug.Print op.outerHTML, "OPTION: " & op.Value
        Ws.Cells(Rw, 5 + n).Value = op.outerHTML
        n = n + 1
    Next op
    Rw = Rw + 1
Next s

End Sub
Thanks Rijnsent!

Sorry to not be able to provide more but have been put on a very short leash. Boss actually wants me to develop a whole regression testing suite using just the Chrome Selenium plug in. :ROFLMAO: I tried to explain that isn't the proper tool, but have been unable to make them see reason. Python and all other tools are forbidden. I know a little VBA so have taken some artistic license to get this Excel up and running. Pretty sure this was forbidden too but forgot to ask.

Thanks again for your thoughts on this. I will definitely try this once I'm back at my desk!

 
Upvote 0
Hi Js,

mmm, that doesn't make my answering of your question much easier, a good practice would be to provide a "minimum reproducable example", but hey, I'll try without :). So I'm coming at this question from a slightly different angle, as I'm not using Selenium, but some default components.
In your situation I would try to see if the site itself makes some API call, so you don't have to go through the forms & pages, but can basically call the backend directly. You can try to see if there are any API calls (normally replying JSON) with the "inspect"->"network" screen. That generally speeds up the scraping process considerably.
Anyhow, what I did below is to pull in a website where I found some dropdowns, listing them, their ID, their CLASS and the options. The pulling in of the website is a bit elaborate, as I'm using the same code to pull in JSON and to create e.g. POST messages.

Hope this helps!


Basic VBA GET/POST call:
VBA Code:
Function WebRequestURL(strUrl As String, strMethod As String, Optional objHeaders As Dictionary, Optional strPostMsg As String) As String

' Instantiate a WinHttpRequest object and open it
ErrResp = "{""error_nr"":ERR_NR,""error_txt"":""ERR_TXT""}"
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.SetTimeouts 5000, 5000, 5000, 120000
'Resolve, Connect, Send and Receive in ms

If strMethod = "GET" Then
    On Error Resume Next
    objHTTP.Open "GET", strUrl
    If Not objHeaders Is Nothing Then
        For Each Key In objHeaders.Keys()
            'e.g. objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
            objHTTP.setRequestHeader Key, objHeaders(Key)
        Next Key
    Else
        'No headers
    End If
   
    objHTTP.send
    If Err.Number = 0 Then
        If objHTTP.Status = "200" Then
            objHTTP.WaitForResponse
            WebRequestURL = objHTTP.responseText
        Else
            WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText)
        End If
    Else
        'Unknown error, probably no internet connection, answer in JSON
        WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description)
    End If
    On Error GoTo 0
ElseIf strMethod = "POST" Then
    On Error Resume Next
    objHTTP.Open "POST", strUrl
    If Not objHeaders Is Nothing Then
        For Each Key In objHeaders.Keys()
            'e.g. objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
            objHTTP.setRequestHeader Key, objHeaders(Key)
        Next Key
    Else
        'No headers
    End If

    If strPostMsg = "" Then
        objHTTP.send
    Else
        objHTTP.send (strPostMsg)
    End If

    If Err.Number = 0 Then
        If objHTTP.Status = "200" Then
            objHTTP.WaitForResponse
            WebRequestURL = objHTTP.responseText
        Else
            WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", objHTTP.Status), "ERR_TXT", "HTTP-" & objHTTP.StatusText)
            Debug.Print objHTTP.responseText
        End If
    Else
        'Unknown error, probably no internet connection, answer in JSON
        WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", Err.Number), "ERR_TXT", "VBA-" & Err.Source & " " & Err.Description)
    End If
    On Error GoTo 0

Else
    WebRequestURL = Replace(Replace(ErrResp, "ERR_NR", 27), "ERR_TXT", "invalid method for WebRequestURL")
End If
Set objHTTP = Nothing

End Function

Specific to loop through all SELECT elements (dropdowns) on a page and get their class, id and options, do make sure you have:
-a sheet named ONE
-in the VBA-editor references (under extra->references) to Microsoft HTML object library and
-Microsoft Scripting Runtime

VBA Code:
Sub GetSelectsAndOptions()

Dim doc As HTMLDocument
Dim Url As String

Set doc = New HTMLDocument

NewLines = ""
Url = "https://getbootstrap.com/docs/4.0/components/forms/"
Dim headerDict As New Dictionary
headerDict.Add "User-Agent", "Mozilla/5.0"
'headerDict.Add "X-Requested-With", "XMLHttpRequest"

ResTxt = WebRequestURL(Url, "GET", headerDict)
doc.body.innerHTML = ResTxt

Rw = 2
Set Ws = Worksheets("ONE")
Ws.Range("A1").Value = "HTML"
Ws.Range("B1").Value = "ID"
Ws.Range("C1").Value = "CLASS"

Ws.Range("E1").Value = "OPTION 1 (etc)"

'Set TblsTd = doc.getElementsByClassName("plusIconTd")
Set TdSel = doc.getElementsByTagName("select")

For Each s In TdSel
    'Debug.Print s.outerHTML
    Ws.Cells(Rw, 1).Value = s.outerHTML
   
    For Each a In s.Attributes
        If a.Name = "id" Then
            'Debug.Print "ID: " & a.Value
            Ws.Cells(Rw, 2).Value = a.Value
        End If
       
        If a.Name = "class" Then
            'Debug.Print "CLASS: " & a.Value
            Ws.Cells(Rw, 3).Value = a.Value
        End If
    Next a
   
    n = 0
    For Each op In s.Options
        'Debug.Print op.outerHTML, "OPTION: " & op.Value
        Ws.Cells(Rw, 5 + n).Value = op.outerHTML
        n = n + 1
    Next op
    Rw = Rw + 1
Next s

End Sub

Hi Rijnsent!

After playing with this, I think I understand you better. Definitely the right idea of what I'm after.

In this instance everything looks to be a form:

HTML:
<form autocomplete="off">
   <div class="grid-col-12 margin-t-20">
      <p data-instructions="instructional_text.how_is_related">1. How is <strong>test botYHIone</strong> related to the other household members?<a href="#" class="instruction_link instruction_link_p" id="instructional_text.how_is_related">Learn more</a></p>
      <div class="text-collapse">
         <div class="hidden">
            <p>Here's some more information about a few of these relationships: <br> <br><strong>Ward:</strong> A person who’s under the care or responsibility of a parent or court-appointed guardian. Wards may be either minor children or disabled adults.<br> <br> <strong>Court-appointed guardian:</strong> An adult who’s been given legal responsibility by the court to mange the affairs of another person. Usually this is an adult who’s given legal responsibility to care for a child, but the guardian can also be an adult with legal responsibility to manage the affairs of another adult.</p>
            <a class="expandable__btn--close" href="#">
               <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11 " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512">
                  <path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
               </svg>
            </a>
         </div>
      </div>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174402_to_1000174429" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">test botYHIone is Spouse botYHIone's</label>
      <select id="page_06_relation_1000174402_to_1000174429" name="relation_1000174402_to_1000174429" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174402_to_1000174430" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">test botYHIone is ChildOne botYHIone's</label>
      <select id="page_06_relation_1000174402_to_1000174430" name="relation_1000174402_to_1000174430" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174402_to_1000174431" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">test botYHIone is ChildTwo botYHIone's</label>
      <select id="page_06_relation_1000174402_to_1000174431" name="relation_1000174402_to_1000174431" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174402_to_1000174432" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">test botYHIone is ChildThree botYHIone's</label>
      <select id="page_06_relation_1000174402_to_1000174432" name="relation_1000174402_to_1000174432" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174402_to_1000174433" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">test botYHIone is ChildFour botYHIone's</label>
      <select id="page_06_relation_1000174402_to_1000174433" name="relation_1000174402_to_1000174433" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-col-12 margin-t-20">
      <p data-instructions="instructional_text.how_is_related">2. How is <strong>Spouse botYHIone</strong> related to the other household members?<a href="#" class="instruction_link instruction_link_p" id="instructional_text.how_is_related">Learn more</a></p>
      <div class="text-collapse">
         <div class="hidden">
            <p>Here's some more information about a few of these relationships: <br> <br><strong>Ward:</strong> A person who’s under the care or responsibility of a parent or court-appointed guardian. Wards may be either minor children or disabled adults.<br> <br> <strong>Court-appointed guardian:</strong> An adult who’s been given legal responsibility by the court to mange the affairs of another person. Usually this is an adult who’s given legal responsibility to care for a child, but the guardian can also be an adult with legal responsibility to manage the affairs of another adult.</p>
            <a class="expandable__btn--close" href="#">
               <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11 " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512">
                  <path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
               </svg>
            </a>
         </div>
      </div>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174429_to_1000174430" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">Spouse botYHIone is ChildOne botYHIone's</label>
      <select id="page_06_relation_1000174429_to_1000174430" name="relation_1000174429_to_1000174430" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174429_to_1000174431" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">Spouse botYHIone is ChildTwo botYHIone's</label>
      <select id="page_06_relation_1000174429_to_1000174431" name="relation_1000174429_to_1000174431" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174429_to_1000174432" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">Spouse botYHIone is ChildThree botYHIone's</label>
      <select id="page_06_relation_1000174429_to_1000174432" name="relation_1000174429_to_1000174432" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174429_to_1000174433" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">Spouse botYHIone is ChildFour botYHIone's</label>
      <select id="page_06_relation_1000174429_to_1000174433" name="relation_1000174429_to_1000174433" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-col-12 margin-t-20">
      <p data-instructions="instructional_text.how_is_related">3. How is <strong>ChildOne botYHIone</strong> related to the other household members?<a href="#" class="instruction_link instruction_link_p" id="instructional_text.how_is_related">Learn more</a></p>
      <div class="text-collapse">
         <div class="hidden">
            <p>Here's some more information about a few of these relationships: <br> <br><strong>Ward:</strong> A person who’s under the care or responsibility of a parent or court-appointed guardian. Wards may be either minor children or disabled adults.<br> <br> <strong>Court-appointed guardian:</strong> An adult who’s been given legal responsibility by the court to mange the affairs of another person. Usually this is an adult who’s given legal responsibility to care for a child, but the guardian can also be an adult with legal responsibility to manage the affairs of another adult.</p>
            <a class="expandable__btn--close" href="#">
               <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11 " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512">
                  <path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
               </svg>
            </a>
         </div>
      </div>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174430_to_1000174431" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">ChildOne botYHIone is ChildTwo botYHIone's</label>
      <select id="page_06_relation_1000174430_to_1000174431" name="relation_1000174430_to_1000174431" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174430_to_1000174432" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">ChildOne botYHIone is ChildThree botYHIone's</label>
      <select id="page_06_relation_1000174430_to_1000174432" name="relation_1000174430_to_1000174432" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174430_to_1000174433" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">ChildOne botYHIone is ChildFour botYHIone's</label>
      <select id="page_06_relation_1000174430_to_1000174433" name="relation_1000174430_to_1000174433" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-col-12 margin-t-20">
      <p data-instructions="instructional_text.how_is_related">4. How is <strong>ChildTwo botYHIone</strong> related to the other household members?<a href="#" class="instruction_link instruction_link_p" id="instructional_text.how_is_related">Learn more</a></p>
      <div class="text-collapse">
         <div class="hidden">
            <p>Here's some more information about a few of these relationships: <br> <br><strong>Ward:</strong> A person who’s under the care or responsibility of a parent or court-appointed guardian. Wards may be either minor children or disabled adults.<br> <br> <strong>Court-appointed guardian:</strong> An adult who’s been given legal responsibility by the court to mange the affairs of another person. Usually this is an adult who’s given legal responsibility to care for a child, but the guardian can also be an adult with legal responsibility to manage the affairs of another adult.</p>
            <a class="expandable__btn--close" href="#">
               <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11 " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512">
                  <path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
               </svg>
            </a>
         </div>
      </div>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174431_to_1000174432" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">ChildTwo botYHIone is ChildThree botYHIone's</label>
      <select id="page_06_relation_1000174431_to_1000174432" name="relation_1000174431_to_1000174432" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174431_to_1000174433" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">ChildTwo botYHIone is ChildFour botYHIone's</label>
      <select id="page_06_relation_1000174431_to_1000174433" name="relation_1000174431_to_1000174433" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
   <div class="grid-col-12 margin-t-20">
      <p data-instructions="instructional_text.how_is_related">5. How is <strong>ChildThree botYHIone</strong> related to the other household members?<a href="#" class="instruction_link instruction_link_p" id="instructional_text.how_is_related">Learn more</a></p>
      <div class="text-collapse">
         <div class="hidden">
            <p>Here's some more information about a few of these relationships: <br> <br><strong>Ward:</strong> A person who’s under the care or responsibility of a parent or court-appointed guardian. Wards may be either minor children or disabled adults.<br> <br> <strong>Court-appointed guardian:</strong> An adult who’s been given legal responsibility by the court to mange the affairs of another person. Usually this is an adult who’s given legal responsibility to care for a child, but the guardian can also be an adult with legal responsibility to manage the affairs of another adult.</p>
            <a class="expandable__btn--close" href="#">
               <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11 " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512">
                  <path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
               </svg>
            </a>
         </div>
      </div>
   </div>
   <div class="grid-row gi-component gi-dropdown">
      <label for="page_06_relation_1000174432_to_1000174433" class="tablet:grid-col-4 gi-dropdown__label undefined iconed-false required-true">ChildThree botYHIone is ChildFour botYHIone's</label>
      <select id="page_06_relation_1000174432_to_1000174433" name="relation_1000174432_to_1000174433" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined">
         <option value="default">Relation</option>
         <option value="19">Child (son or daughter)</option>
         <option value="31">Court-Appointed Guardian</option>
         <option value="53">Domestic partner</option>
         <option value="05">Grandchild (grandson or granddaughter)</option>
         <option value="04">Grandparent (grandfather or grandmother)</option>
         <option value="13">Mother-in-law or Father-in-law</option>
         <option value="03">Parent (father or mother)</option>
         <option value="14">Sibling (brother or sister)</option>
         <option value="11">Son-in-law or Daughter-in-law</option>
         <option value="01">Spouse</option>
         <option value="17">Stepchild (stepson or stepdaughter)</option>
         <option value="16">Stepparent (stepfather or stepmother)</option>
         <option value="15">Ward</option>
         <option value="G9">Other</option>
      </select>
   </div>
</form>


Looks like the select id and name both have the same value. What I am trying to do is get something like this in a worksheet:

page_06_relation_1000174402_to_1000174429
page_06_relation_1000174402_to_1000174430
page_06_relation_1000174402_to_1000174431
page_06_relation_1000174402_to_1000174432
page_06_relation_1000174402_to_1000174433
page_06_relation_1000174429_to_1000174430
page_06_relation_1000174429_to_1000174431
page_06_relation_1000174429_to_1000174432
page_06_relation_1000174429_to_1000174433
page_06_relation_1000174430_to_1000174431
page_06_relation_1000174430_to_1000174432
page_06_relation_1000174430_to_1000174433
page_06_relation_1000174431_to_1000174432
page_06_relation_1000174431_to_1000174433
page_06_relation_1000174432_to_1000174433

I've got a workaround for the most immediate need but feel this skill will come in handy the farther down this rabbit hole this project goes. Thanks for the help and furthering my education!
 
Upvote 0
This code does exactly that, it's a slight modification of my code:

VBA Code:
Sub ProcessHTML()

    filenm = "C:\Users\rijns\Documents\development\form_file.html"
    
    Dim oFSO As Object
    Dim oFS As Object, sText As String
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFS = oFSO.OpenTextFile(filenm)
    Do Until oFS.AtEndOfStream
        sText = oFS.ReadAll()
        'Debug.Print sText
    Loop

    Set doc = New HTMLDocument
    doc.body.innerHTML = sText
    
    Set TdSel = doc.getElementsByTagName("select")
    Rw = 1
    For Each s In TdSel
        For Each a In s.Attributes
            If a.Name = "id" Then
                'Debug.Print "ID: " & a.Value
                Worksheets("TWO").Cells(Rw, 1).Value = a.Value
            End If
        Next a
        Rw = Rw + 1
    Next s

    'Or alternatively
    Rw = Rw + 1
    Worksheets("TWO").Cells(Rw, 1).Value = "ALTERNATIVE"
    Rw = Rw + 1
    Set TdSel = doc.getElementsByTagName("select")
    For Each s In TdSel
        Worksheets("TWO").Cells(Rw, 1).Value = s.ID
        Rw = Rw + 1
    Next s

End Sub

Excel VBA debug 101:
I assume you're working in the VBE (Visual Basic Editor) and have the "Immediate" and "Local Variables" windows switched on, like so (dutch version, but it should look about the same).

1691484405605.png

Next, when you run code, use break points: either by clicking in front of the line or using F9:
1691484507463.png


After setting your break points, run your code by either pressing the start button or F5. Note: sometimes it is much smarter to run your code step by step, using F8. Your code will stop when it hits a break point, like so. Here I ran the code to the break point and after that pressed F8 two times to run those lines of code one by one.
What you see:
  • in the Direct window, the results of Debug.Print show up, this can be helpfull to see where in your code you are and/or to check results. E.g. in this example, the Rw variable has the value 18
  • That same value for Rw can also be found in the "Local variables" window (just outside view in this screenshot).
  • That same Local Variables window can be used to inspect the various variables in your code to e.g. see what properties they have and what values they hold. Sometimes it's worth debug.printing a property of an object/variable to see the value.

1691484673710.png


Good luck VBA-ing :-)
 

Attachments

  • 1691484927151.png
    1691484927151.png
    35.1 KB · Views: 6
Upvote 0
Solution
This code does exactly that, it's a slight modification of my code:

VBA Code:
Sub ProcessHTML()

    filenm = "C:\Users\rijns\Documents\development\form_file.html"
   
    Dim oFSO As Object
    Dim oFS As Object, sText As String
   
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFS = oFSO.OpenTextFile(filenm)
    Do Until oFS.AtEndOfStream
        sText = oFS.ReadAll()
        'Debug.Print sText
    Loop

    Set doc = New HTMLDocument
    doc.body.innerHTML = sText
   
    Set TdSel = doc.getElementsByTagName("select")
    Rw = 1
    For Each s In TdSel
        For Each a In s.Attributes
            If a.Name = "id" Then
                'Debug.Print "ID: " & a.Value
                Worksheets("TWO").Cells(Rw, 1).Value = a.Value
            End If
        Next a
        Rw = Rw + 1
    Next s

    'Or alternatively
    Rw = Rw + 1
    Worksheets("TWO").Cells(Rw, 1).Value = "ALTERNATIVE"
    Rw = Rw + 1
    Set TdSel = doc.getElementsByTagName("select")
    For Each s In TdSel
        Worksheets("TWO").Cells(Rw, 1).Value = s.ID
        Rw = Rw + 1
    Next s

End Sub

Excel VBA debug 101:
I assume you're working in the VBE (Visual Basic Editor) and have the "Immediate" and "Local Variables" windows switched on, like so (dutch version, but it should look about the same).

View attachment 96776
Next, when you run code, use break points: either by clicking in front of the line or using F9:
View attachment 96777

After setting your break points, run your code by either pressing the start button or F5. Note: sometimes it is much smarter to run your code step by step, using F8. Your code will stop when it hits a break point, like so. Here I ran the code to the break point and after that pressed F8 two times to run those lines of code one by one.
What you see:
  • in the Direct window, the results of Debug.Print show up, this can be helpfull to see where in your code you are and/or to check results. E.g. in this example, the Rw variable has the value 18
  • That same value for Rw can also be found in the "Local variables" window (just outside view in this screenshot).
  • That same Local Variables window can be used to inspect the various variables in your code to e.g. see what properties they have and what values they hold. Sometimes it's worth debug.printing a property of an object/variable to see the value.

View attachment 96778

Good luck VBA-ing :)

Thanks Rijnsent!

I appreciate the help and suggestions.

Still struggling with writing loops but this definitely helps. Hope you have a great rest of the week! :)
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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