1

I am writing a code where i have to check that on clicking on some button, an assessment should get opened. On opening assessment it should check if there a radio button kind of question or checkbox. Tick on the answer accordingly and click on the next button. This needs to be done until the last question. Note: On selection and for a ques, the next button becomes active.

The problem is that I am not being able to understand how can I make this dynamic that it should understand how many questions are there in an assessment as it is not fixed that there would be the same no of questions in it?

I am also not being able to use if condition in it. Does testcafe support it?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

1 Answers1

1

You can iterate through the set of elements using the nth method.

For example:

test('Click all checkboxes', async t => {
    const checkboxes = Selector('input[type="checkbox"]');
    const checkboxCount = await checkboxes.count;

    for (let i = 0; i < checkboxCount; i++)
        await t.click(checkboxes.nth(i));
});

Also, here is an example of how to use the if condition to check if the element exists: https://stackoverflow.com/a/47363579/10684943.

Dmitry Ostashev
  • 2,305
  • 1
  • 5
  • 21