Donate

Webbrowser GetAttribute("class") Method Not Working

When working with Webbrowser's GetAttribute() method, you often encountered an issue wherein GetAttribute("class") does not work as expected.
1
2
3
if (Element.GetAttribute("class").Contains("_textFontColor")) {
    //other codes here
}
After investigating from MSDN docs, I found out a comment below the documentation which states that you have to use className instead of class. Well, that did the trick. :-)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
HtmlElementCollection elements = WebBrowser1.Document.GetElementsByTagName("A");
foreach (HtmlElement Element in elements) {
    if (Element.GetAttribute("className").Contains("_textFontColor")) {
        //other codes here
    }
}
 
HtmlElementCollection elements = WebBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement Element in elements) {
    if (Element.GetAttribute("className").Contains("_textFontColor")) {
        //other codes here
    }
}
Reference (See Bottom Comment of the page): HtmlElement.GetAttribute Method

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations