What is the correct way to run a jQuery .click() in a selenium test? The element being clicked is a hyperlink.
HTML:
<div id="buttons">
<a class="button" id="btnRun" href="javascript:void(0)">Run</a>
</div>
<div id="output" />
jQuery
$(document).ready(function () {
$('#btnRun').click(function () {
$("#output").html("hello world");
});
})
Selenium:
[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"));
}
When I run the test the button click does not occur, and after the 2nd WaitForPageToLoad
, the test finishes and reports failure (because the text hello world was not found, because the button click never occurred)