使用网络浏览器 WatiN

发布于 2024-09-19 11:36:17 字数 296 浏览 5 评论 0原文

我使用以下代码将 watin 绑定到 winform 上的网络浏览器。

Dim w As IE = New IE(WebBrowser1.ActiveXInstance)
Settings.AutoStartDialogWatcher = False
w.GoTo("http://google.com")

我可以从wireshark 中看到页面已加载,但表单被冻结,直到抛出异常“Internet Explorer 忙时超时”。

有没有办法将 watin 绑定到 webbrowser 控件?

I'm using the following code to bind watin to a webbrowser on the winform.

Dim w As IE = New IE(WebBrowser1.ActiveXInstance)
Settings.AutoStartDialogWatcher = False
w.GoTo("http://google.com")

I can see from wireshark that the page get's loaded, but the form is frozen until a exception gets thrown "Timeout while Internet Explorer busy".

Is there a way to bind watin to the webbrowser control ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凯凯我们等你回来 2024-09-26 11:36:17

首先,我认为这一行:

Settings.AutoStartDialogWatcher = False

应该位于开头,在创建 IE 实例之前。

如果您在单独的线程中运行您的代码,它将会工作。

C# 代码(抱歉):

var thread = new Thread(() =>
{
    Settings.AutoStartDialogWatcher = false;
    var ie = new IE(webBrowser1.ActiveXInstance);
    ie.GoTo("http://www.google.com");
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

First of all, I think that this line:

Settings.AutoStartDialogWatcher = False

should be at the beginning, before IE instance is created.

Your code will work if you run it in separate thread.

Code in C# (sorry):

var thread = new Thread(() =>
{
    Settings.AutoStartDialogWatcher = false;
    var ie = new IE(webBrowser1.ActiveXInstance);
    ie.GoTo("http://www.google.com");
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
﹏雨一样淡蓝的深情 2024-09-26 11:36:17

如果我使用此代码,它会起作用

ie = New IE(WebBrowser1.ActiveXInstance)
ie.GoToNoWait("http://google.com")
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
  Application.DoEvents()
End While

如果它不是最好的解决方案,但它对我有用

If I use this code it works

ie = New IE(WebBrowser1.ActiveXInstance)
ie.GoToNoWait("http://google.com")
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
  Application.DoEvents()
End While

If it is not the best solution, but it works for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文