Verify sorting in Selenium Verify sorting in Selenium selenium selenium

Verify sorting in Selenium


Before checking it with selenium, You have to do small thing. Store the table values(which comes after sorting) in a string or array.

Now perform the sorting using selenium and capture the new list as

string new_list= selenium.gettable("xpath");

Now compare both the values and check whether they are same or not.


I have shared a strategy to test sorting feature of an application on my blog. You can use this to automate test cases that verify the sorting feature of an application. You could use it on place like the search result page, item listing and report module of the application. The strategy explained does not require creation of test data and is fully scalable.


You can get value of fields like this:

 //div[@id='sortResult']/div[1]/div  (this'd be row 1 of the search result) //div[@id='sortResult']/div[2]/div   ( row 2)

(I'm making some assumptions about the HTML structure here, but you get my drift...)

These can be quite fragile assertions, I'd recommend you anchor these xpath references to an outer container element (not the root of your document, as lots of "automatic" tools do).

When you click sort, the value changes. You'll have to find out what the values are supposed to be.

Also watch out for browser compatibility with such xpaths. They're not always ;)