I'm developing a windows form application to parse and analyze web pages. I used webbrowser control. The web page has html and javascript code bellow. and my windows form has c# code. Here is the code:
HTML code:
<div id="div1" onclick='func1(this);'>
</div>
<div id="div2">
</div>
<div id="div3">
</div>
Javascript:
function func1(element) {
...
}
document.getElementById("div2").onclick = function foo() { doSomething(); }
document.getElementById("div3").addEventListener("click", anyFunc);
C# code in my windows form application after navigating the related URL:
HtmlElement el1 = WebBrowser.Document.GetElementById("div1");
HtmlElement el2 = WebBrowser.Document.GetElementById("div2");
HtmlElement el3 = WebBrowser.Document.GetElementById("div3");
String el1JavaFunc = el1.GetAttribute("onClick");
String el2JavaFunc = el2.GetAttribute("onClick");
String el3JavaFunc = el3.GetAttribute("onClick");
// check if el1JavaFunc is empty or null
// check if el2JavaFunc is empty or null
// check if el3JavaFunc is empty or null
In this way after checking the related string for each element, I can figure that if the element has assigned javascript function or not. This works for el1 and el2, but it returns null string for el3.
How could I figure that third element has assigned javascript function using addEventListener?