Is there any way which would allow me to use watin's functionalities from my web browser control? simply i want to use watin with my web browser control i don't want my application to open a new window ,i need it in my web browser control.
Create your IE object using a WebBrowser2 interface from your web browser control, something like:
var CurrentBrowser = new IE(WebBrowser2);
One important point is to be sure to set AutoStartDialogWatcher
to false in WatiN settings. Since you are not implementing IE anymore, you are responsible for all dialogs.
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.