If you are using .Net WebBrowser Control you can create WatiN's IE
object by using following code:
var ie = new IE(webBrowser.ActiveXInstance);
But if you do that inside your Form_Load
ActiveXInstance
will be null. And if you do that for example inside some kind of button_Click
the application will hang after you use eg. ie.GoTo
. You need to start new thread and operate there. For example:
private void Form1_Load(object sender, EventArgs e)
{
var t = new Thread(() =>
{
Settings.AutoStartDialogWatcher = false;
var ie = new IE(webBrowser1.ActiveXInstance);
ie.GoTo("http://www.google.com");
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
You need to disable auto start of dialog watcher, because you cannot use built in WatiN dialog watcher. But with a little bit of hacking you can create your own based on original DialogWatcher
class. Handling popups and creating new web browser controls are also possible.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…