Pagination in selenium using core java

Pagination Solution One:

  • Find the pagination elements by using findElemnts() and store as list of elements.
  • Get the pagination size.
  • Check pagination exist or not.
  • If exist make a loop and click until last pagination size.
Ex:


List<webElement> pagination =driver.findElemnts(By.xpath("//div[@class='nav-pages']//a")); 
// checkif pagination link exists 

if(pagination .size()>0){ 
sop("pagination exists"); 

// click on pagination link 

for(int i=0; i<pagination .size(); i++){ 
pagination.get(i).click(); 

} else { 
sop("pagination not exists"); 



Pagination Solution Two:

  • Find the pagination elements by using findElemnts() and store as list of elements.
  • Get the pagination size.
  • Get Last Page Number.
  • Find Next Button of pagination.
  • Check pagination exist or not by taking pagination size.
  • If exist make a loop and click until last pagination number.
Ex:


List<webElement> pagination =driver.findElemnts(By.xpath("//div[@class='nav-pages']//a")); 


webElement NextButton= driver.findElemnt(By.xpath("//*[@id='nextbutton id']"))

int LastPageNumber = (int)driver.findElemnt(By.xpath("//*[@text='>>]/preceding::/span[1]")); 

// checkif pagination link exists
if(pagination .size()>0)

sop("pagination exists"); 

// click on pagination link 

for(int i=1; i <LastPageNumber; i++)

      
    NextButton.click();


} else { 
sop("pagination not exists"); 



Pagination Solution Three:
  • Find the pagination elements by using findElemnts() and store as list of elements.
  • Get the pagination size.
  • Get Last Page Number.
  • Find Next Button for pagination.
  • Check pagination exist or not by taking pagination size.
  • Then check Nextbutton is enable or not.If enable go inside loop and clcik next button until it's not disable.
  • If exist make a loop and click until last pagination number.
Ex:

List<webElement> pagination =driver.findElemnts(By.xpath("//div[@class='nav-pages']//a")); 


webElement NextButton= driver.findElemnt(By.xpath("//*[@id='nextbutton id']"));

webElement prevButton= driver.findElemnt(By.xpath("//*[@id='prevButtonid']"));

int LastPageNumber = (int)driver.findElemnt(By.xpath("//*[@text='>>]/preceding::/span[1]")); 

// checkif pagination link exists
if(pagination .size()>0)
sop("pagination exists"); 

// click on pagination link 

for(int i=1; i <pagination .size(); i++)

//Check if nextbutton is enable or not.

   if(NextButton.isEnabled())
{

    NextButton.click();
}
else { 
sop("pagination not exists"); 
}}

1 comment:

  1. Thank you @qalearningguide for great post. You solved a tof scenario for me. Keep posting

    ReplyDelete

Copyright © 2017 QALEARNINGGUIDE.COM || ALL RIGHTS RESERVED