WatiN with webbrowser

2019-06-01 02:34发布

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 ?

2条回答
Anthone
2楼-- · 2019-06-01 03:12

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();
查看更多
闹够了就滚
3楼-- · 2019-06-01 03:18

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

查看更多
登录 后发表回答