Alex
Alex

Reputation: 145

How do I use a WebBrowser to get an element by ID or class attribute?

I know that in a WebBrowser you can use Document.GetElementById to find an element by its name attribute, but I want to search the webpage for an element using the id or class atributes, how would it be possible to do this in a WebBrowser? I want to make it click on an image tag.

<td id="button1-cell"><img src="/static/button1.png" alt="Button 1" id="but1"></td>

Also, is it possible to InvokeMember("click") on divs?

Upvotes: 1

Views: 9260

Answers (1)

John Koerner
John Koerner

Reputation: 38077

GetElementById's documentation says that it gets an element by ID, not name. If you want to find an element by name, you can use

webBrowser1.Document.All("name")

Upvotes: 3

Related Questions