Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Testcafe:重复单击,直到出现另一个元素_Javascript_Async Await_Functional Testing_E2e Testing_Testcafe - Fatal编程技术网

Javascript Testcafe:重复单击,直到出现另一个元素

Javascript Testcafe:重复单击,直到出现另一个元素,javascript,async-await,functional-testing,e2e-testing,testcafe,Javascript,Async Await,Functional Testing,E2e Testing,Testcafe,我正在用testcafe测试一个用户界面 要求用户单击某个按钮,直到出现模式对话框,然后用户应单击对话框中的某个按钮 测试中的点击次数可能会有所不同,有时是两次,有时是三次。因此,这段代码并不总是有效的 await t .click(Button) .click(Button) .click(Button) .click(ModalDialogButton); 我需要一种方法反复单击按钮,直到出现ModalDialogButton。然后,必须单击ModalDialogButto

我正在用testcafe测试一个用户界面

要求用户单击某个按钮,直到出现模式对话框,然后用户应单击对话框中的某个按钮

测试中的点击次数可能会有所不同,有时是两次,有时是三次。因此,这段代码并不总是有效的

await t
  .click(Button)
  .click(Button)
  .click(Button)
  .click(ModalDialogButton);
我需要一种方法反复单击
按钮
,直到出现
ModalDialogButton
。然后,必须单击
ModalDialogButton


如何使用testcafe实现这一点?

您可以尝试使用
while
循环实现这一点,如下所示:

while (!(await ModalDialogButton.exists))
    await t.click(Button)

await t.click(ModalDialogButton);
能否请您澄清您对重复点击的需求?也许您可以等待
ModalDialogButton
存在。例如:

await ModalDialogButton();

该行自动等待,直到页面上出现默认超时的
ModalDialogButton
选择器。您可以增加。

谢谢,等待解决方案成功了!