【发布时间】:2011-04-06 03:24:34
【问题描述】:
在硒测试中运行 jQuery .click() 的正确方法是什么?被点击的元素是一个超链接。
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");
});
})
硒:
[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"));
}
当我运行测试时,按钮点击没有发生,在第二次WaitForPageToLoad之后,测试完成并报告失败(因为没有找到文本hello world,因为按钮点击从未发生)
【问题讨论】:
-
在你的 jQuery 代码中,你需要把 $("#output").html("hello world");
-
对不起,这只是一个例子,当手动点击按钮时,它确实做了一些事情(加载一个 jqgrid)。但在测试中,点击甚至没有执行
标签: c# jquery testing selenium selenium-rc