I have a form with the webBrowser1 control, which is used to load a page that contains the following line in its html:
... <div class="cls"> Hello World ! </div>
I need to get the InnerText of a div element. I tried using the following code:
string result = ""; foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("div")) if (el.GetAttribute("class") == "cls") { result = el.InnerText; }
But the above code does not work! and according to decision 1 for a similar issue on another site , it says:
The first thing that caught my attention: <div class="thin"> does not define the name of the div element, it defines the CSS style class. Instead, use the attribute name (or both), for example: <div class="thin" name="thin"> .
How can I get innerText from a div if there is only a class attribute?
Any help would be greatly appreciated
source share