gpbl
gpbl

Reputation: 4804

Testcafe: repeat click until another element appears

I'm testing a user interface with testcafe.

The user is asked to click a button until a modal dialog appears, then it should click on a button in the dialog.

The number of clicks may vary in the test, sometimes is two, sometimes three. Thus, this code doesn't always work

await t
  .click(Button)
  .click(Button)
  .click(Button)
  .click(ModalDialogButton);

I need a way to repeatedly click Button until ModalDialogButton appears. Then, ModalDialogButton must be clicked.

How can I do this with testcafe?

Upvotes: 1

Views: 1581

Answers (1)

Artem
Artem

Reputation: 921

You can try to do this using the while loop like the following:

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

await t.click(ModalDialogButton);

Could you please clarify your need for repeatedly clicks? Maybe you can just wait for ModalDialogButton to exist. For example:

await ModalDialogButton();

This line automatically waits until the ModalDialogButton selector appears on the page with the default timeout. You can increase the selector timeout.

Upvotes: 3

Related Questions