Discussion:
[.NET 2.0] WebBrowser control - attributes?
(too old to reply)
Jeff Johnson
2009-09-01 17:54:09 UTC
Permalink
Has anyone else had trouble getting attributes from HtmlElement objects
contained in the HtmlDocument object (what you get with the Document
property)? I loaded some (valid) HTML via the DocumentText property and when
I do something like

webBrowser1.Document.Body.Children[1].GetAttribute("class")

(where this child element happens to be a DIV tag and definitely has a class
attribute) I get an empty string. However, if I use the DomElement property
of this HtmlElement and cast it to mshtml.HTMLDivElement, I can then
(through some nasty casting and retrieving of enumerators), finally dig down
and get the value of this attribute. Anyone else experienced something like
this?

(And why in the world didn't MS put an Attributes collection on the
HtmlElement class to begin with??)

Before you ask: Yes, the document has fully loaded by the time I run the
code above.
Jeff Johnson
2009-09-01 18:44:59 UTC
Permalink
However, if I use the DomElement property of this HtmlElement and cast it
to mshtml.HTMLDivElement, I can then (through some nasty casting and
retrieving of enumerators), finally dig down and get the value of this
attribute.
For what it's worth, I just discovered the wonderful IHTMLDOMNode interface,
which I have switched to using instead of HTMLDivElement, just in case
anyone was gonig to point that out. Original question still holds, though.
valencia
2009-11-11 20:01:47 UTC
Permalink
valencia wilkinson
akimo feeman
ashimo feeman
mark foase
go paunl
lat
Post by Jeff Johnson
Has anyone else had trouble getting attributes from HtmlElement objects
contained in the HtmlDocument object (what you get with the Document
property)? I loaded some (valid) HTML via the DocumentText property and
when I do something like
webBrowser1.Document.Body.Children[1].GetAttribute("class")
(where this child element happens to be a DIV tag and definitely has a
class attribute) I get an empty string. However, if I use the DomElement
property of this HtmlElement and cast it to mshtml.HTMLDivElement, I can
then (through some nasty casting and retrieving of enumerators), finally
dig down and get the value of this attribute. Anyone else experienced
something like this?
(And why in the world didn't MS put an Attributes collection on the
HtmlElement class to begin with??)
Before you ask: Yes, the document has fully loaded by the time I run the
code above.
Loading...