C# 我如何使用 Document.GetElementById("NAME").Click?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11271875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:13:12  来源:igfitidea点击:

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

c#clickgetelementbyid

提问by Minicl55

Possible Duplicate:
How do you click a button in a webbrowser control in C#?

可能的重复:
如何在 C# 中单击 webbrowser 控件中的按钮?

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;

我使用的代码是: browser.Document.GetElementById("ap_h").Click;

采纳答案by Stefan Keller

The piece of code you are looking for is:

您正在寻找的一段代码是:

Invoke a method in the DOM-Element

调用 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.

上面的代码为您在 WebBrowser 控件中执行单击。



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
}