How to getelement by class?

There is nothing built-in in the WebBrowser control to retrieve an element by class name. Since you know it is going to be an a element the best you can do is get all a elements and search for the one you want:

var links = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement link in links)
{
    if (link.GetAttribute("className") == "show1")
    {
        //do something
    }
}

Leave a Comment