cy.document().then(document => {
const arra = [...document.querySelectorAll('.instances__action')];
for (let i = 1; i <= arra.length; i++) {
let state = document.querySelector(
`#root > section > section > main > div > div > section.instances > div > div > div > div > div > div > table > tbody > tr:nth-child(${i}) > td:nth-child(3) > span`
).innerText;
if (state !== 'Finished') {
document
.querySelector(
`#root > section > section > main > div > div > section.instances > div > div > div > div > div > div > table > tbody > tr:nth-child(${i}) > td:nth-child(7) > div > button.ant-btn.ant-btn-primary.ant-btn-sm`
)
.click();
} else {
continue;
}
}
});
here, suppose the arra.length is 2. on each iteration button is clicked.
I want to do it one at a time. At first, it should check if the state is finished or not.
If the state is not finished it should press the button and wait until the state becomes finished.
After that, it should go to the next iteration. In my current implementation, It goes to the second iteration before the first iteration is finished.