C# Watin触发的onchange事件中的对话框
我有一个带有下拉菜单的网站。当用户更改下拉列表时,会出现一个确认对话框,询问他们是否希望更改下拉列表。如果单击“是”,则继续,否则将保持不变。相当标准的东西 然而,当我开始编写Watin单元测试时,我感到很痛苦 My html是一个简单的选择列表,id为_stateList 这是我的javascript:C# Watin触发的onchange事件中的对话框,c#,jquery,unit-testing,watin,C#,Jquery,Unit Testing,Watin,我有一个带有下拉菜单的网站。当用户更改下拉列表时,会出现一个确认对话框,询问他们是否希望更改下拉列表。如果单击“是”,则继续,否则将保持不变。相当标准的东西 然而,当我开始编写Watin单元测试时,我感到很痛苦 My html是一个简单的选择列表,id为_stateList 这是我的javascript: $(function() { $('#_stateList').change(function() { if(confirm('Are you sure you wis
$(function() {
$('#_stateList').change(function() {
if(confirm('Are you sure you wish to change your state?'))
//do something
});
});
因此,在Watin中,我有一个引发更改事件的扩展方法:
public static void SelectWithChangeEvent(this SelectList selectList, string text)
{
selectList.Select(text);
string js = string.Format("$('#{0}').change();", selectList.Id);
InternetExplorer.Browser.Eval(js); //This is where it hangs
}
该扩展方法在此处调用:
ConfirmDialogHandler dialogHandler = new ConfirmDialogHandler();
using (new UseDialogOnce(InternetExplorer.Browser.DialogWatcher, dialogHandler))
{
PageMapping.StateDropdown.SelectWithChangeEvent(stateName); //It never gets past here
dialogHandler.WaitUntilExists(5);
if(dialogHandler.Exists())
dialogHandler.OKButton.Click();
else
Assert.Fail("No Dialog Appeared");
}
我真的希望这不是太多的代码,但我根本不知道如何处理在更改事件而不是单击事件中触发的对话框。在Watin中,按钮具有ClickNoWait()。Select有类似的产品吗?还是评估?或者是一个说“不要等待”的设置
感谢您的帮助。原因之一可能是您忘记结束if声明 你的密码是:
i$(function() {
$('#_stateList').change(function() {
if(confirm('Are you sure you wish to change your state?')
//do something
}))
虽然它应该是:
$(function() {
$('#_stateList').change(function() {
if(confirm('Are you sure you wish to change your state?')){
//do something
}
});
在setTimeout(函数(){})中包装javascript;将允许Eval异步返回
public static void SelectWithChangeEvent(this SelectList selectList, string text)
{
selectList.Select(text);
string js = string.Format("setTimeout(function() {{$('#{0}').change();}}, 5);", selectList.Id);
InternetExplorer.Browser.Eval(js); //This is where it hangs
}
如果语句不需要大括号,则为一行。还有,这不是问题所在。好吧,那是我的错。只是大声思考;)