c# generates JS to fill webform: how to verify it works?
<p>as continuation to:</p>

<blockquote>
  <p><a href="http://stackoverflow.com/questions/4269800/c-webbrowser-control-in-a-new-thread/4271581#4271581">C# WebBrowser Control in a new thread</a></p>
  
  <p><a href="http://stackoverflow.com/questions/7531444/how-to-fill-an-external-web-form-with-c-application/7532112#7532112">how to fill an external web form with c# application?</a></p>
</blockquote>

<p>I want to fill a website (i.e. gmail) web-form.
I thought to avoid the WebBrowser control overhead. I used JS. 
but the following code doesn't work (as the Navigation_completed handler is called too many times). How can I verify the following code works? Is there any faster way to do so ?</p>

<pre><code>static void Main(string[] args)
{
    runBrowserThread(new Uri("https://accounts.google.com/ServiceLogin?service=mail&amp;passive=true&amp;rm=false&amp;continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&amp;bsv=llya694le36z&amp;ss=1&amp;scc=1&amp;ltmpl=default&amp;ltmplcache=2&amp;hl=iw&amp;from=logout"));

}

private static void runBrowserThread(Uri url)
{
    var th = new Thread(() =&gt;
    {
        var br = new WebBrowser();
        br.DocumentCompleted += browser_DocumentCompleted;
        br.Navigate(url);
          br.Navigate("javascript: void(document.getElementsByName('Email')[0].value = 'Name';document.getElementsByName('Passwd')[0].value = 'Pass'; document.getElementsByName('signIn')[0].click();)");                                
        Application.Run();
    });
    th.SetApartmentState(ApartmentState.STA);
    th.Start();
}

static void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    var br = sender as WebBrowser;
    if (br.Url == e.Url)
    {
        Console.WriteLine("Natigated to {0}", e.Url);
      //  Application.ExitThread();   // Stops the thread
    }
}
</code></pre>

<p>TIA</p>
