我正在使用 testcafe 测试用户界面。
要求用户单击按钮,直到出现模态对话框,然后应单击对话框中的按钮。
点击次数在测试中可能会有所不同,有时是两次,有时是三次。因此,这段代码并不总是有效
await t
.click(Button)
.click(Button)
.click(Button)
.click(ModalDialogButton);
我需要一种方法来重复单击 Button
直到出现 ModalDialogButton
。然后,必须单击 ModalDialogButton
。
我如何使用 testcafe 做到这一点?
最佳答案
您可以尝试使用 while
循环来执行此操作,如下所示:
while (!(await ModalDialogButton.exists))
await t.click(Button)
await t.click(ModalDialogButton);
您能否说明您需要重复点击?也许您可以等待 ModalDialogButton
出现。例如:
await ModalDialogButton();
此行自动等待,直到 ModalDialogButton
选择器出现在默认超时的页面上。您可以增加 selector timeout .
关于javascript - Testcafe:重复点击直到出现另一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55987042/