Scenario: I'm using CodeceptJS to automate:
- creating a new record on a table (paginates on 20 records)
- searching the table for the record
- if the record can be found on the first page, click it
- else click the next button and try search until the record is found.
I can easily find the record if it's on the first page by searching the table div and inserting the newRecordID. But I'm struggling to write an if/else loop that'll iterate through each page until the record is found. The below code also doesn't click the next button for some reason.
My best attempt:
let searchID = {xpath: "//div[normalize-space()= '"+ newRecordID +"'][1]"};
if (searchID) {
I.click(searchID); //I click the id if found
I.wait(2);
I.say("found it");
}
else {
I.click(locatorsPage.locators.nextButton); //clicks the next page button
I.click(searchID);
I.wait(2);
I.say("found it on another page");
}
I tried something along this line but no luck yet:
do {
I.click(searchID);
I.wait(2);
I.say("found it");
if (searchID) {
I.seeElementInDOM(searchID);
} else {
I.click(locatorsPage.locators.nextBtn);
I.click(searchID);
I.wait(2);
I.say("found it second page")
}}
while (!searchID);
});