javascript Selenium IDE - 如何处理 java 脚本警报和确认
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14788118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium IDE - How to handle java-script alerts and confirmations
提问by Abhi
I am novice to automation testing and have started using Selenium IDE as the choice for automation.
我是自动化测试的新手,并且已经开始使用 Selenium IDE 作为自动化的选择。
I just want to know if there is any way to handle java-script alerts using IDE.
我只想知道是否有任何方法可以使用 IDE 处理 java 脚本警报。
Take a scenario: I am clicking on "Delete" button and there comes a java-script alert box with OK and Cancel options, but Xpath can not identified for these elements.On the other hand, when I make a script for click event on delete button and run it using Selenium IDE, the element gets automatically deleted.
假设一个场景:我点击“删除”按钮,出现一个带有 OK 和 Cancel 选项的 java 脚本警告框,但 Xpath 无法识别这些元素。另一方面,当我为点击事件编写脚本时删除按钮并使用 Selenium IDE 运行它,该元素将被自动删除。
So, guys please help. Leave a reply in case my question needs to be elaborated.
所以,请各位大侠帮忙。如果我的问题需要详细说明,请留下回复。
Thanks in advance.
提前致谢。
采纳答案by Petr Jane?ek
Take a look at the documentation. The main part is this:
查看文档。主要部分是这样的:
When running under Selenium, JavaScript pop-ups will not appear. This is because the function calls are actually being overridden at runtime by Selenium's own JavaScript. However, just because you cannot see the pop-up doesn't mean you don't have to deal with it. To handle a pop-up, you must call its
assertFoo(pattern)
function. If you fail to assert the presence of a pop-up your next command will be blocked and you will get an error similar to the following[error] Error: There was an unexpected Confirmation! [Chose an option.]
在 Selenium 下运行时,不会出现 JavaScript 弹出窗口。这是因为函数调用实际上在运行时被 Selenium 自己的 JavaScript 覆盖了。但是,仅仅因为您看不到弹出窗口并不意味着您不必处理它。要处理弹出窗口,您必须调用其
assertFoo(pattern)
函数。如果您未能断言弹出窗口的存在,您的下一个命令将被阻止,您将收到类似于以下内容的错误[error] Error: There was an unexpected Confirmation! [Chose an option.]
回答by Nikhil Surendran
java-script alerts in ide can be handle using selenium commands storeAlert and
IDE 中的 java 脚本警报可以使用 selenium 命令 storeAlert 和
storeConfirmation what it will do is it Retrieves the message of a JavaScript confirmation or alert dialog generated during the previous action. this commands can be put at the position where the alert will occur
storeConfirmation 它将做的是检索在上一个操作期间生成的 JavaScript 确认或警报对话框的消息。这个命令可以放在警报发生的位置
command:storeAlert
命令:storeAlert
Target:variableName
目标:变量名
command:storeConfirmation
命令:存储确认
Target:variableName
目标:变量名
variable name is the variable in which the occurred alert will store
变量名称是发生的警报将存储在其中的变量
Thank you..
谢谢..