views:

536

answers:

5

I have a c# windows form project using watin.

I would love to attach to the web-browser control on a form, is this possible? Is there any sample code on how to attach to the embedded web-browser control.

//Looks like this only works for actual IExplorer instances.
window = WatiN.Core.Browser.AttachTo<WatiN.Core.IE>(WatiN.Core.Find.ByTitle("Google"));
A: 

Perhaps i'm missing something here, but can you not use a WebBrowser control and attach it to the WinForms application?

Kyle Rozendo
I have a WebBrowser control on my form. I want to attach to the instance of the browser control using Watin.
MHop
A: 

Yes, you can use a WebBrowser control, but there are tricks.

The key point is that because your application is providing the dialogs (not IE), you must set the Settings object property AutoStartDialogWatcher to false. Otherwise, you will fail on attachment because the dialog watcher window handle is invalid.

I would suggest using something like: IE newbrowser = new WatiN.Core.IE(embeddedbrowser.IWebBrowser2);

...of course the IWebBrowser2 property name will change depending on the library you use.

Daaron
A: 

This is code I used to attach to the Embeded Web Browser Control:

WatiN.Core.IE window = null;
WatiN.Core.Settings.AutoStartDialogWatcher = false;
window = new WatiN.Core.IE(webBrowser1.ActiveXInstance);

MHop
+1  A: 

For me it gave the error.

WatiN.Core.Exceptions.TimeoutException was unhandled Message="Timeout while Internet Explorer busy" Source="WatiN.Core"

Unknwn
A: 

Same here. It is giving same problem. But if I use

ShDocVw.InternetExplorer ie=new InternetExplorer() ; ie.visible=true ; ie.Navigate1("myurl");

it shows new IE window ( to make sure the reference to ShDocVw and all that is correct

onemore