简体   繁体   English

C# Webbrowser 文档,invokemember(“click”),是否可以等到单击操作解决?

[英]C# Webbrowser document , invokemember(“click”), is it possible to wait until that click action is resolved?

What I have going on is a Invokemember("Click"), the problem is I want to be able to grab the resulting innerhtml.我正在做的是一个 Invokemember("Click"),问题是我希望能够获取生成的 innerhtml。 The problem is i'm unsure of how/if it's possible to wait until the resulting action of the invokemember("click") is resolved.问题是我不确定如何/是否可以等到调用成员(“点击”)的结果操作得到解决。 Meaning, in a javascript when you perform this click it will take you ot the next 20 items listed.意思是,在 javascript 中,当您执行此单击时,它将带您进入接下来列出的 20 个项目。 However, i'm unsure of how to tell when that javascript will be fully loaded.但是,我不确定如何判断 javascript 何时会满载。 Below is what I'm using.下面是我正在使用的。

private void button1_Click(object sender, EventArgs e)
{
    HtmlElement button = webBrowser1.Document.GetElementById("ctl08_ctl00_InventoryListDisplayFieldRepeater2_ctl00_BlockViewPaging_Next");
    button.InvokeMember("click");
    HtmlElement document = webBrowser1.Document.GetElementsByTagName("html")[0];


}

One possible solution is to modify your "click" event handler in javascript so it changes the value of some hidden input field right before exiting the method (after all work is done).一种可能的解决方案是修改 javascript 中的“单击”事件处理程序,以便在退出方法之前更改某些隐藏输入字段的值(在所有工作完成之后)。 You can attach to the event of changing field from C# code and act when it's fired.您可以从 C# 代码附加到更改字段的事件,并在它被触发时采取行动。

// Your init method - you can call it after `InitializeComponent`
// in the constructor of your form
Init() {
    webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}

void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
    webBrowser1.Document.GetElementsByTagName("statusField")[0].AttachEventHandler("onchange", WorkDone);
}

void WorkDone(object sender, EventArgs e) {
    HtmlElement document = webBrowser1.Document.GetElementsByTagName("html")[0];
}

That's the raw solution, I haven't yet checked whether "onchange" is a correct DOM event.这是原始解决方案,我还没有检查"onchange"是否是正确的 DOM 事件。

Also, you can't attach to DOM events before the document is completely loaded, that's why I put the attaching logic in the handler of DocumentCompleted event.此外,您不能在文档完全加载之前附加到 DOM 事件,这就是为什么我将附加逻辑放在DocumentCompleted事件的处理程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM