问题
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;
回答1:
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
}
来源:https://stackoverflow.com/questions/11271875/how-do-i-use-document-getelementbyidname-click