I am trying to detect a certain element when it's clicked in a web browser.
Here's my code:
try
{
htmlElement.MouseDown -= new
HtmlElementEventHandler(webBrowser1_MouseDown);
}
catch (Exception)
{
}
htmlElement.MouseDown += new HtmlElementEventHandler(webBrowser1_MouseDown);
This code is called on webBrowser1.GotFocus & webBrowser1.LostFocus.
Here is the code for MouseDown.
public void webBrowser1_MouseDown(object sender, HtmlElementEventArgs e)
{
HtmlElement element = e.ToElement;
Console.WriteLine(element);
}
For some reason whenever I click on the item. element is equal to null?
but if I do
try
{
Console.WriteLine(htmlElement.Name); // works
htmlElement.MouseDown -= new
HtmlElementEventHandler(webBrowser1_MouseDown);
}
catch (Exception)
{
}
htmlElement.MouseDown += new HtmlElementEventHandler(webBrowser1_MouseDown);