How do I use Document.GetElementById("NAME").Click?

c#, click, getelementbyid

Solution

The piece of code you are looking for is:

Invoke a method in the DOM-Element

// The WebBrowser control
System.Windows.Forms.WebBrowser webBrowser;

// Perform a click on an element
HtmlDocument document = webBrowser.Document;
document.GetElementById("id_of_element").InvokeMember("Click");

The code above performs the click in the WebBrowser Control for you.

Assign an event handler

If you want to assign an event handler:

document.GetElementById("id_of_element").Click 
                             += new HtmlElementEventHandler(el_Click);

with:

void el_Click(object sender, HtmlElementEventArgs e)
{
     // Do something
}

Problem

Possible Duplicate: How do you click a button in a webbrowser control in C#? I tried just doing it normally, but it kept telling me it needed to be on the other side of a = or +=. How do I fix this? The code I'm using is: browser.Document.GetElementById("ap_h").Click;

Original source

Related problems