We can handle the pagination in cypress by fetching the page indexes and comparing it with the targeted text or element found.
In the below example, we are targeting the text “$12” that is within the Webtable, such that fetching the webtable rows and columns and finding if the targeted element is found or not, else move to the next page.
describe('Sahithi Cypress Pagination Test',function () {beforeEach(() => { cy.visit('https://examples.bootstrap-table.com/template.html?v=134&url=options%2Ftable-pagination.html')cy.wait(2000) })it('Pagination Cypress Test',function () {constpageFetch= (pageIndex, length) => {if (pageIndex == length) {return; }returncy.get("li > .page-link").eq(pageIndex).click({ force:true }).wait(5000) //clicks on page index.then(() => {returngetRowLength().then((rowLength) => {returnrowFetch(0, rowLength, pageIndex, length); }); }); };constrowFetch= (rowIndex, length, pageIndex, pageLength) => {if (rowIndex == length) {returnpageFetch(++pageIndex, pageLength); }returncy.get("tr > td").eq(rowIndex).then(($itemPriceList) => {constItemPrice=$itemPriceList.text();cy.wait(500)if (ItemPrice =="$12") {//Enters the condition if the Item text Foundcy.log("Yes! is found");cy.get('tr > td').eq(rowIndex) //gets the columns with index.then(function (pricelist) { //stores text found in pricelistconstPrice=pricelist.text();expect(Price).to.contains('$12'); //Assert text found })//Do something if found in the page…….returnnewCypress.Promise((resolve) => {resolve("Success"); }); }returnrowFetch(++rowIndex, length, pageIndex, pageLength); }); };constgetRowLength= () => {returncy.get("td:nth-child(1)").then(($list) => {returnnewCypress.Promise((resolve) => {resolve($list.length); }); }); };//For Each Pagination - Searching the Price first - Such that pulling the no.of pages into list $pagelistcy.get("li > .page-link").then(($pagelist) => {returnpageFetch(0,$pagelist.length); }) })})