开发者

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 a开发者_C百科ble to grab the resulting 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. However, i'm unsure of how to tell when that javascript will be fully loaded. 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). You can attach to the event of changing field from C# code and act when it's fired.

// 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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜