I am trying to make an application that generates an event (any event) when a button is pressed in a HTML (web browser) control in WPF. I have searched so far and tried various implementations but no luck. I am also attaching the most recent attempt, I was able to manipulate the values in html, read from html but no luck in getting an event when a button is pressed.
public void webBrowser_LoadCompleted()
{
HTMLDocument doc = (HTMLDocument)webBrowser.Document;
IHTMLElementCollection theElementCollection = doc.getElementsByTagName("input");
foreach (IHTMLElement curElement in theElementCollection)
{
string uiAuto = curElement.getAttribute("fname").ToString();
if (uiAuto == "")
{
curElement.setAttribute("value", "changed value!");
}
if (uiAuto == "...")
{
curElement.setAttribute("value", "...");
}
if (curElement.getAttribute("value") == "Login")
{
curElement.click();
}
}
}
The html
<!DOCTYPE html>
<html>
<head>
<title> Testing HTML </title>
</head>
<body>
<h1>Hi there!</h1>
<button type="button">Click Me!</button>
<input type="text" value="login" id="fname" name="fname"><br>
<h2>Bye!</h2>
</body>
</html>
I am new to WPF and given this task to complete today. Just want to raise an event in my C# application when button is pressed in html along with some attributes, for example, data in textbox.
I also tried writing a javascript and using invokeScript() in webBrowser but that too didn't end up well.
Looking forward to some help, thank you.