Reputation: 37632
How to cast mshtml.IHTMLDivElement to mshtml.HTMLDivElementClass?
IHTMLElementCollection collection = doc.body.all;
foreach (var htmlElem in collection)
{
if (htmlElem is mshtml.IHTMLDivElement)
{
mshtml.IHTMLDivElement div = htmlElem as mshtml.IHTMLDivElement;
if (div != null)
{
// HTMLDivElementClass divClass = (HTMLDivElementClass)div; ?????????
}
}
}
I need to access HTMLDivElementClass to be able to get all members of it.
Upvotes: 1
Views: 2740
Reputation: 56
Your code almost correct. Not sure what you want.
Please change your code like below
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;
foreach (var htmlElem in collection)
{
if (htmlElem is mshtml.IHTMLDivElement)
{
mshtml.HTMLDivElementClass div = htmlElem as mshtml.HTMLDivElementClass;
if (div != null)
{
//DO YOUR CODE HERE
//div.IHTMLElement_id
}
}
}
It is working for me and in "div" object is of the type "HTMLDivElementClass"
And one more suggestion if you want to all the DIV tag only from the page then use the following line of code.
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.getElementsByName("div");
Instead of
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;
That will remove your condition to check element is DIV or not.
Hope this help to you.
Upvotes: 1