title: C# Selenium RC - How to test a jQuery button click?
body: <p>What is the correct way to run a jQuery .click() in a selenium test?  The element being clicked is a hyperlink.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div id="buttons"&gt;
      &lt;a class="button" id="btnRun" href="javascript:void(0)"&gt;Run&lt;/a&gt;
  &lt;/div&gt;
  &lt;div id="output" /&gt;
  </code></pre>
  
  <p>jQuery</p>
  
  <pre><code>$(document).ready(function () {
      $('#btnRun').click(function () {
         $("#output").html("hello world");
      });
  })
  </code></pre>
  
  <p>Selenium:</p>
  
  <pre><code>[Test]
  public void TestOutput()
  {
      selenium_local = new DefaultSelenium("localhost", 4444, 
                                           "*firefox", "https://localhost");
      selenium_local.Start(); 
  
      selenium_local.Open("/TestPage");
      selenium_local.WaitForPageToLoad("30000");
      Assert.That(selenium_local.IsElementPresent("id=btnRun"), Is.True);
  
      selenium_local.Click("id=btnRun");
      Thread.Sleep(5000);
  
      // also tried without success:
      // selenium_local.FireEvent("id=btnRun","click");
      // selenium_local.Click("xpath=//a[@id='btnRun']");
      // selenium_local.Click("dom=document.getElementById('btnRun')");
  
      Assert.That(selenium.GetValue("id=output"), Is.EqualTo("hello world"));
  }
  </code></pre>
  
  <p>When I run the test the button click does not occur, and after the 2nd <code>WaitForPageToLoad</code>, the test finishes and reports failure (because the text hello world was not found, because the button click never occurred)</p>