It seems that the class can be obtained using a special attribute name: element.GetAttribute( "className" ).
C# Getting Attribute Value from HtmlElement
Rico Strydom
1
Reputation point
I am getting an HtmlElement from a click.
HtmlElement element = WebBrowser.Document.GetElementFromPoint(e.ClientMousePosition);
This neatly returns an
HtmlElement
with Id (loginUserName
), OuterHTML (<input class="form-control ng-pristine ng-untouched ng-isolate-scope ng-invalid ng-invalid-required" id="loginUserName" required="" type="text" placeholder="Username" ng-enter="ok()" ng-model="user.username" surec-focus="true">) etc.
When I try to get the value of the "class" attribute with ...
string classNameValue = element.GetAttribute("class");
... it returns an empty string.
Any idea why the method is unable to retrieve the attribute value?
Bizarre part is that ...
string elementId = element.GetAttribute("id");
and
string elementType = element.GetAttribute("type");
...do return values.