0

I want to click event button in webbrowser object.

Button is clicked I want to reach out and write the code? For example, the login button is clicked on the webbrowser object in the pop-up on the site to capture the event and would like to write the code?

1
  • Do you want to get event of clicked button on html page? Commented Apr 9, 2013 at 12:46

2 Answers 2

7

I write an example for you(how get event clicked button):

private void Form1_Load(object sender, EventArgs e) { //Or navigate to your url webBrowser1.DocumentText = "<html><body><button id=\"btn1\" type=\"button\">Click Me!</button><button id=\"btn2\" type=\"button\">Click Me!</button></body></html>"; } 

Call Click event:(when page loaded)

 private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { webBrowser1.Document.Click += new HtmlElementEventHandler(Document_Click); } 

Get Active Element When User click on document

 void Document_Click(object sender, HtmlElementEventArgs e) { //Check Element is Button if (webBrowser1.Document.ActiveElement.TagName == "BUTTON") { if (webBrowser1.Document.ActiveElement.Id== "your button id") { //Do someting } } } 
Sign up to request clarification or add additional context in comments.

Comments

1

If I understand correctly, you're using the WebBrowser control in C# WinForms and you would like to fire an event when a button is clicked.

The control doesn't have a click event, but the Document does. To do this you can use WebBrowser.Document.Click event and then loop through the HTML elements to find the one that was clicked.

web.Document.Click += new HtmlElementEventHandler(Document_Click);

This link will help also: webbrowser-control-get-element-by-type

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.