Storing Web Table With Pagination Data Into List Of Map – Java

A Web Table with pagination is very common in an application. In this post we will learn how to store all rows and columns of a Web Table with pagination in a List of Map using Java.

Already we have learnt :-

Storing Web Table Data Into List Of Map – Java

Storing Web Table Data Into A List Of Maps Using Java Stream APIs

WHAT IS WEB TABLE?

A table is made of rows and columns. When we create a table for a web page, that is called as a web table. In HTML, a web table is created using <table> tag. Web table is a HTML structure for creating rows and columns on a Web page.

A web table can consists below parts:

  1. Header(s): It is created using <th> tag.
  2. Row(s):It is created using <tr> tag.
  3. Columns(s):It is created using <td> tag.

A typical web table’s first row is marked as header and from second row onward, it stores values. Table headers can be grouped using <thead> and remaining row can be grouped as <tbody>. Last row can also be grouped as <tfoot>. An example is shown below:-

Example Web Table

If you save above html code as <someName>.html and open a web browser, you will see output as below:-

Web Table with pagination

Pagination of paging in a Web Table divides records in number of pages. For example if you need to show 100 records, you can show 10 records in one page and user can navigate to next set of records using pagination.

Below is an example of WebTable with pagination :-

Above Web Table will look like as below :-

We table with pagination

So we need to go through all pages of web table and fetch data. Pagination implementation may be different in each table. For example :- In above table, you see a “Next” button which takes you next page of web table. It gets disable when there is no further page i.e if you are at page No 6, Next button will be disabled. We can use this condition to decide for number of iteration in code.

There can be another way where you can find the total pagination count and then iterate from Page 1 to N where N is total pages count.

How to wait till a page is loaded in web table

This is very important in reading rows and columns of a particular page. When you click on Next or any page number directly, it takes some time to load, If we do not wait till data for particular row is displayed, we may end up with either reading data of previous page in stead of next page or StaleElementReferenceException (Depends how you are using locator).

So for above table, when you are on a page say 1, you will see class name consists “current” as shown below:-

Web table with pagination

We need to wait till “current” is added to class name of desired page. Another way is to wait till we get updated entries text. If we are on page 1, we see “Showing 1 to 10 of 57 entries” and when we are on page 2, we see “Showing 11 to 20 of 57 entries”.

Step by step logic

  1. Get the table headers and store in a List as we need to maintain insertion order.
  2. We will store each row in to a LinkedHashMap and all LinkedHashMap in to a List.
  3. Get first row of a page. Get all cells of first row and store cell data in to a Map where header name is key and cell is value. We need to iterate header list of Step 1 simultaneously.
  4. Repeat the same process for all rows of first page.
  5. Now we need to go to next page. We will get the current page first then click on Next button and wait till the next page gets “current” in its class attribute. The same we need to do in loop till we get last page.

Complete Java Code

Output

You can clone code from my git repo.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related post here, all API manual and automation related posts here and find frequently asked Java Programs here.

Many other topics you can navigate through menu.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Writing technical posts and creating YouTube videos are my hobbies.

4 thoughts on “Storing Web Table With Pagination Data Into List Of Map – Java

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.