Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
466 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...