Selenium-RC 无法处理确认框
我正在测试一个网络应用程序,我从列表中删除一个项目。单击删除后,应用程序会要求确认。 Selenium IDE 将其检测为确认框。当我通过 RC (C#) 运行代码时,它甚至捕获确认框,执行该确认框上的删除按钮的单击,但是,确认框在屏幕上永远不可见。此外,它只点击删除按钮;该项目不会被删除。我手动尝试过,效果很好。
请帮助,我是 Selenium 的新手,尝试在多个论坛中找到答案,但没有成功。
代码如下:
string confirmation;
for (int second = 0;; second++) {
if (second >= 60) Assert.Fail("timeout");
try
{
confirmation=selenium.GetConfirmation();
if ((confirmation == " Delete confirmation message")) break;
}
catch (Exception e)
{
PrintLog("Error while waiting for confirmation. Error: "+e.Message);
}
Thread.Sleep(1000);
}
try
{
Assert.IsTrue(confirmation == "Delete confirmation message");
}
catch (AssertionException e)
{
PrintLog(e.Message);
}
selenium.FireEvent("//a[@id='btnOkConfirm']","click");
在最后一条语句之后,所选项目必须被删除并且页面应该刷新,但是什么也没有发生。我只能看到“Javascript:;”写在 Firefox 窗口的状态栏中。我猜想让 javascript href 在 selenium-rc 中工作是有问题的。
谢谢,
瓦米普
I am testing a web app where i delete an item from a list. Upon clicking on delete, the app asks for confirmation. Selenium IDE detects it as a confirmation box. When I run the code thro' the RC (C#), it even catches the confirmation-box, executes the click of delete button on that confirmation box, but, the confirmation box is never visible on the screen. Further, it only clicks on the delete button; the item doesn't get deleted. I tried it manually, works fine.
Please help, I'm new to Selenium and tried to find the answers at multiple forums without any success.
Here's the code:
string confirmation;
for (int second = 0;; second++) {
if (second >= 60) Assert.Fail("timeout");
try
{
confirmation=selenium.GetConfirmation();
if ((confirmation == " Delete confirmation message")) break;
}
catch (Exception e)
{
PrintLog("Error while waiting for confirmation. Error: "+e.Message);
}
Thread.Sleep(1000);
}
try
{
Assert.IsTrue(confirmation == "Delete confirmation message");
}
catch (AssertionException e)
{
PrintLog(e.Message);
}
selenium.FireEvent("//a[@id='btnOkConfirm']","click");
After the last statement, the selected item must get deleted and page should refresh, but, nothing happens. All I can see is "Javascript:;" written in the status bar of the firefox window. I guess its problematic to get javascript hrefs working in selenium-rc.
Thanks,
Vamyip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有许多命令可以处理 JavaScript 确认。默认情况下,Selenium 将在确认时选择“确定”,除非您发送
chooseCancelOnNextConfirmation
命令。为了使用确认信息,您需要使用 getConfirmation 命令。上述命令的 Selenium 参考:
此外,如果您的
click
命令未显示JavaScript 确认您可能会发现相应的事件没有被触发。您可以尝试使用mouseDown
和mouseUp
命令,或fireEvent
命令。There are a number of commands to deal with JavaScript confirmations. Selenium will by default choose 'OK' at a confirmation, unless you send the
chooseCancelOnNextConfirmation
command. In order to consume the confirmation you will need to use thegetConfirmation
command.Selenium reference for above commands:
Additionally, if your
click
command is not showing the JavaScript confirmation you might find that the appropriate event is not being fired. You could try using themouseDown
andmouseUp
commands, or thefireEvent
command.最近,我发现这种行为是由于 selenium 的架构(更准确地说,它的基于 javascript 的核心)而发生的。当我手动进行测试并保持 selenium IDE 打开时,会复制此行为。所以,我认为目前还没有立即解决这个问题的办法。如果我找到解决方法,我会在这里发布。
感谢戴夫的回复。
更新:开发团队告诉我,没有与同时运行的 selenium IDE 一起调用 JavaScript 函数。这确实是 Selenium 的 Javascript 核心的问题。
感谢所有花时间回答这个问题的人。
问候,
瓦米普
Lately, I've discovered that this behavior is occurring due to the architecture of selenium(more precisely, its javascript based core). when I do the test manually, keeping the selenium IDE open, this behavior is replicated. So, I think there's no immediate solution to this problem right now. Will post here if I find a workaround.
Thanks to Dave for replying.
Update: The development team informed me that a javascript function is not being called with selenium IDE running alongside. This indeed is a problem with Selenium's Javascript core.
Thanks to everybody who took time to respond to this question.
Regards,
Vamyip