1

folks, I am intermediate in selenium and Java. I have tried to googled-out for the solution but not understand well.

Can anyone please suggest me how to verify sorting functionality of table using selenium web driver (with java). Please provide the explanation with the examples it would be helpful for me.
Here is the Table link

Thanks in advance!

2
  • What do you want to verify in sorting ? Do you have any data that you want to match with each value one by one and finally say all matching ?
    – NarendraR
    Commented Sep 7, 2017 at 11:29
  • i want check if click on field header its sort Ascending Order , click twice than its sort in Descending Order Commented Sep 7, 2017 at 11:32

2 Answers 2

2

As you are intermediate, I will just write out the pseudocode for the logic.

  1. Click the header of the column you wish to sort.
  2. Create a list of the cell values of the sorted column by repeating these steps:

    • Fetch all values from current page
    • Go to next page if there is one
  3. Run a compare method on the list to see if the values are in order (either ascending or descending). Look through some answers here. Because WebElements are found from top to bottom, the order you see them on the page should be preserved in the list.

Note: it's possible that Selenium starts getting cell values before the sort action is finished. In this case, add a waiting mechanism after step 1.

-1

Its simple

Follow the below steps

  1. Create a Method or Google for a Method that checks whether the passed Collection is in ascending order or not
  2. Same way create a Method that checks whether the passed Collection is in descending order or not
  3. Now in the Application, Click on the Sorting i.e ascending or descending as you need
  4. Loop across each Data store them in any Collection
  5. If clicked ascending, Pass the stored values to ascending method or vice versa
  6. If the above method returns true, the Test is PASS
1
  • 1
    This doesn't add anything over the existing answer.
    – c32hedge
    Commented Dec 18, 2017 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.