Is there a possibility to address elements on a website which have no ID?

You will need to use some type of selector.

The GetElementByID method works best because if the HTML file is formatted correctly then there should only be one element with that unique ID.

The GetElementFromPoint will return an element based on the X,Y coordinate of the document, this is best used in the Document’s Click event.

The GetElementByTagName name will return a collection of elements and works if you know the tag type of the element, such as <button>...</button> or <p>...</p>. To help narrow down which element you want, you will need to then iterate through the returned collection and compare either the element’s attributes if you know their respective values or the element’s text via the InnerHTML property.

The last and least effective method is the All property which returns every element in the document. The reason why this is the least effective is because at least with GetElementByTagName, you can narrow down the collection based on the tag’s name.

However, let’s assume that you have the following markup:

<body>
  <p>Look at my super complex HTML markup.</p>
  <button>Click Me</button>
  <button>No, click me!</button>
</body>

You could then get the button tag that says “Click Me” by using the following:

Dim click_me As HtmlElement = WebBrowser1.Document.GetElementByTagName("button").SingleOrDefault(Function(e) e.InnerHtml = "Click Me")

Leave a Comment