How to Obtain a Webpage’s HTML Element Using Inspection For

How to Obtain a Webpage's HTML Element Using Inspection For

In this example, we are using the popular Chrome Browser, although many other browsers have the same method for inspecting HTML elements.

  1. Locate the element in question (in our case, the “Post Your Question” button).

  2. Right-click the element

  3. Chose the drop-down item Inspect

enter image description here

This will bring up the F12 Developer Tools. This toolbox will automatically highlight your element.

enter image description here

As you can see, your element has a few options to reference it. The best method is using its ID, as this is always a unique value.

This element’s ID is submit-button-42, which you found in this:

In VBA, you can set a variable to this element by:

Dim IE As InternetExplorer, myElement As Object Set IE = New InternetExplorer Set myElement = IE.document.getElementByID(“submit-button-42”)

Unfortunately, not every element has an ID. This element is included in a couple collections as well. The issue with collection items is that many other elements may also be included within that same collection – meaning that it’s not a unique value.

In our example, there are two collections we can refer to: class and tag. The ClassName is btn__with-icon, which we see from:

Leave a Reply