如何让WebBrowser等待Javascript? [英] How to make WebBrowser wait for Javascript?

查看:86
本文介绍了如何让WebBrowser等待Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

首先这里是我的代码:

Hello Friends
First of all here are my codes:

this.WebBrowser.Navigate(string.Format("http://facenama.com/{0}", "MeysamTM"));

while (this.WebBrowser.ReadyState != WebBrowserReadyState.Complete)
   Application.DoEvents();

foreach (string contact in this.Contacts.Items)
{
    this.WebBrowser.Document.InvokeScript("postform_open");

    object[] args = new object[1] { contact };

    this.WebBrowser.Document.InvokeScript("postform_sharewith_user", args);

    this.WebBrowser.Document.Window.Frames[0].Document.GetElementsByTagName("body")[0].InnerHtml = this.Message.Text;

    this.WebBrowser.Document.InvokeScript("postform_submit");
}



这部分代码使用WebBrowser向网站中的多个用户发送消息(至少假设)。但总是会将消息发送到列表中的最后一个联系人。

我想如果我在foreach循环结束时让JavaScripts等待,问题就会解决。

你怎么看?甚至可能吗?


These part of my code sends a message to several users in a website using WebBrowser (It suppose to, at least). But always the message will be send to last contact in the list.
I think if I make JavaScripts wait at the end of the foreach loop the problem will be fix.
What do you think? Is that even possible?

推荐答案

我终于找到了!



有些任务无法重复我使用WebBrowser时的单一方法。我不明白为什么?!我刚用一个Timer来避免这个问题。我的意思是循环的每一步都将在Timer.Tick()处理程序方法中运行;您应该注意必须进行一些更改,例如定义Fields而不是局部变量和控制异常。



我希望我的问题及其答案对其他人有帮助。
I find out finally!

Some Tasks can not repeat in a single method when I am working with WebBrowser. I did not understand why?! I just used a Timer to avoid this issue. I mean every step of the loop will run in Timer.Tick() handler method; You should attention that some changes must be done such as defining Fields instead of local variables and controlling exceptions.

I hope My Question and its answer will be helpful for others.


这篇关于如何让WebBrowser等待Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆