Selenium IDE - 如何处理 JavaScript 弹窗和确认框

3
我是自动化测试的新手,开始使用Selenium IDE进行自动化。我想知道是否有任何方法可以使用IDE处理JavaScript警报。
以一个场景为例:我点击“删除”按钮,然后出现了一个带有OK和Cancel选项的JavaScript警报框,但XPath无法识别这些元素。另一方面,当我制作一个单击删除按钮的脚本并使用Selenium IDE运行它时,该元素会自动被删除。
所以,请大家帮忙。如果需要澄清我的问题,请回复。
提前致谢。
2个回答

2

请查看文档,其中主要内容如下:

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.]

关于警告框的详细步骤请参见手册。


0

使用Selenium命令storeAlert和storeConfirmation可以处理IDE中的JavaScript警报。它会检索前一操作期间生成的JavaScript确认或警报对话框的消息。这些命令可以放置在警报将出现的位置。

命令:storeAlert

目标:variableName

命令:storeConfirmation

目标:variableName

变量名是将存储发生的警报的变量。

谢谢。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接