how to get the IDs of HTML elements only which are visibile on webpage like textbox,combobox, radioboutton, combobox at a time using VBA

StackOverflow https://stackoverflow.com/questions/16849465

Question

I have created a tool where it takes all the HTml input elements IDs with tagname as input and store this IDs in excel sheet with their Values and when i wanted to change the values in the webpage i can change the values in excel and update webpage using another macro, till this it is working fine but the main problem is when i get all the input elements by tag name input i am getting the IDs which are not visible like sessionID and some variables in the webpage along with the visible items , i dont need these elements which are not visible to the user. How to get the element IDs which are vislbe to the user and with which he can interact?? I have googled enough for a solution and ended up here, please help me. I have used the fllowing codes to get element IDs

Set TDelements = IEfr0.getElementsByTagName("input")
If Sheets(sheetname).Cells(1, 1).Value = "" Then

     r = 0
     For Each TDelement In TDelements

     Sheets(sheetname).Range("A1").Offset(r, 0).Value = TDelement.Name
     Sheets(sheetname).Range("A1").Offset(r, 1).Value = TDelement.Value
        r = r + 1

         Next

        Set TDelements = IEfr1.getElementsByTagName("a")
       For Each TDelement In TDelements
         If TDelement.innerText = "Next" Then
         TDelement.Click
          End If

       Next
Else
Was it helpful?

Solution

You could try to check it this way:

If TDelement.isContentEditable = True Then

'... your code here like:
 Sheets(sheetname).Range("A1").Offset(r, 0).Value = TDelement.Name
 Sheets(sheetname).Range("A1").Offset(r, 1).Value = TDelement.Value
    r = r + 1

End if

It works for sample HTML page I've tested it with. However, your HTML page could have different way of setting attributes of HTML tags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top