How do I use Document.GetElementById(“NAME”).Click? [duplicate]

大城市里の小女人 提交于 2019-12-17 20:29:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!