Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
nag6789
Posts : 1
Join date : 2014-06-10

How to Sort List<WebElements> Empty How to Sort List<WebElements>

Tue Jun 10, 2014 9:14 pm
Details Steps are below.
1. Opened Ebay Site
2. Searched for LED TV
3. Captured prices of the results
    List uiAllPrices = oBrowser.findElements(By.xpath("//td[@class='prc']/div//div[@itemprop='price']/span"));

For example: If 3 types of LED TV's shown up in the results with the Prices like 20, 10, 50

4. Now I would like to sort the values captured in uiAllPrices.
Example: 10, 20, 50 or 50, 20, 10

Any of your help will be greatly appreciated.
Advisor
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
https://seleniumforum.forumotion.net

How to Sort List<WebElements> Empty Re: How to Sort List<WebElements>

Mon Jun 23, 2014 8:42 pm
hi,

Best way to store all values of list in Map/Dictionary and then sort on the basis of value.

if your using java, refer following link otherwise find same solution for your prog lang:
http://www.mkyong.com/java/how-to-sort-a-map-in-java/
avatar
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

How to Sort List<WebElements> Empty Re: How to Sort List<WebElements>

Fri Jul 18, 2014 7:35 pm
Code:
Collections.sort(uiAllPrices );
avatar
Rajasekhar
Posts : 1
Join date : 2014-07-24

How to Sort List<WebElements> Empty Re: How to Sort List<WebElements>

Thu Jul 24, 2014 5:53 pm
Hi,
   Iam giving the code for sorting the list

List namesList=new ArrayList();
namesList.add("Ravi");
namesList.add("Gopal");
namesList.add("Arun");
System.out.println(namesList);
Collections.sort(namesList);
System.out.println(namesList);


Last edited by Rajasekhar on Wed Jul 30, 2014 8:10 pm; edited 3 times in total (Reason for editing : http://www.indiumsoft.com/core-qa-offerings/test-automation)
avatar
nabhanya.varma
Active particpant
Active particpant
Posts : 13
Join date : 2014-03-02

How to Sort List<WebElements> Empty Re: How to Sort List<WebElements>

Sat Sep 13, 2014 5:30 pm
Please try below
List allOptions = se.getOptions();
// create one list
List list = new ArrayList(Arrays.asList(allOptions));

System.out.println("List value before: "+list);

// sort the list
Collections.sort(list);
Sponsored content

How to Sort List<WebElements> Empty Re: How to Sort List<WebElements>

Back to top
Permissions in this forum:
You cannot reply to topics in this forum