title: Is it possible to use Selenium with C# windows Form that contains a WebBrowser object?
body: <p>I'm wondering if it's possible to use Selenium with a C# Windows Form 
  that contains a WebBrowser object.  </p>
  
  <p>I'm using selenium
  and I'm able to create test cases with the Selenium script record; I'm 
  just trying to pinpoint whether or not I can export the C# code and 
  have it all run within a C# environment.  I appreciate any thoughts or 
  explanations. </p>
  
  <p><strong>update</strong>
  I got to the point to have Selenium open the WinForm which contains the WebBrowser Component. However from there my test won't execute. Looks like it doesn't understand selenium command. I don't see any error messages being thrown though. hmmm</p>
  
  <p>The thing is <code>winformWithWebBrowserTest</code>.exe which opens winForm with webbrowser is opened.
  But nothing happens. Below code is the one that fires up the .exe</p>
  
  <p><strong>test code (Selenium command)</strong></p>
  
  <pre><code>namespace ClassLibrary1
  {
      class Class2
      {
          private ISelenium selenium;
          private StringBuilder verificationErrors;
  
          [SetUp]
          public void SetupTest()
          {
  
              selenium = new DefaultSelenium
                  ("localhost", 4444, "*custom C:\\Users\\m-tak\\Documents\\Visual Studio 2010\\Projects\\winformWithWebBrowserTest\\winformWithWebBrowserTest\\bin\\Release\\winformWithWebBrowserTest.exe", "http://www.livemocha.com");
  
              selenium.Start();
              verificationErrors = new StringBuilder();
          }
  
          [TearDown]
          public void TeardownTest()
          {
              selenium.Stop();
          }
  
          [Test]
          public void TheUntitledTest()
          {
              //nothing here gets executed :(
              Console.WriteLine("foobar front");
              selenium.Open("/");
              Console.WriteLine("foobar");
              selenium.WaitForPageToLoad("30000");
              selenium.Open("/users/logout");
              selenium.Open("/users/login");
  
  
          }
  
      }
  }
  </code></pre>
  
  <p><strong>.exe</strong></p>
  
  <pre><code>namespace WindowsFormsApplication1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
          {
             //this gets executed always......
              HtmlElement head = webBrowser1.Document.GetElementsByTagName("body")[0]; 
              HtmlElement scriptOne = webBrowser1.Document.CreateElement("script");
              IHTMLScriptElement element = (IHTMLScriptElement)scriptOne.DomElement;
              element.text = "function sayHello() { " + 
                  "alert('hello');" +
                  " }" ;
              head.AppendChild(scriptOne);
              webBrowser1.Document.InvokeScript("sayHello");
  
  
          }
          //getter setter..... 
          public WebBrowser getWebBrowser() 
          {
              return this.webBrowser1;
  
          }
          public void setWebBrowser(WebBrowser wb) 
          {
              this.webBrowser1 = wb;
          }
  
          //just address bar
          private void button1_Click(object sender, EventArgs e)
          {
              if (!string.IsNullOrEmpty(textBox1.Text))
              {
                  webBrowser1.Navigate(textBox1.Text);
              }
          }
  
          //just address bar
          private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
          {
              if (textBox1.Text != e.Url.ToString())
              {
                  textBox1.Text = e.Url.ToString();
              }
          }
  
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I made my test simple so now I don't use NUnit. I've created C# console app just to run the c# .exe file. But in my console it would output <code>"--1--"</code> and "<code>--2--"</code> only..</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Web;
  using Selenium;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
  
              Console.WriteLine("-- 1---");
              ISelenium selenium;
  
  
              selenium = new DefaultSelenium
                  ("localhost", 4444, "*custom C:\\Users\\m-takayashiki\\Documents\\Visual Studio 2010\\Projects\\winformWithWebBrowserTest\\winformWithWebBrowserTest\\bin\\Release\\winformWithWebBrowserTest.exe", "http://www.livemocha.com");
  
              Console.WriteLine("-- 2---");
  
              selenium.Start();
  
              Console.WriteLine("-- 3---");
  
  
              selenium.Open("/");
              selenium.WaitForPageToLoad("30000");
              selenium.Open("/users/logout");
              selenium.Open("/users/login");
  
  
              Console.WriteLine("test test test");
  
              //tear down
              selenium.Stop();
  
          }
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I checked RC log:</p>
  
  <pre><code>15:40:35.379 DEBUG [13] org.openqa.jetty.http.HttpContext - Handler org.openqa.selenium.server.SeleniumDriverResourceHandler in HttpContext[/selenium-server,/selenium-server]
  15:40:35.380 DEBUG [13] org.openqa.selenium.server.SeleniumDriverResourceHandler - req: POST /selenium-server/driver/ HTTP/1.1
  Content-Type: application/x-www-form-urlencoded; charset=utf-8
  Host: localhost:4444
  Content-Length: 247
  Expect: 100-continue
  Connection: keep-alive
  
  15:40:45.408 DEBUG [13] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for window 'null' local frame 'null' for 1790 more secs
  15:40:45.408 DEBUG [13] org.openqa.selenium.server.FrameGroupCommandQueueSet - waiting for condition for 1000 more ms
  15:40:45.945 DEBUG [12] org.openqa.selenium.server.FrameGroupCommandQueueSet - got condition? : false
  </code></pre>