java - How to Sort WebElements in a ArrayList in WebDriver? -
please how sort below piece of code find max,min , average ? want navigate question has views , use selenium take screen shot of question's page using https://stackoverflow.com/ home page sample page
list<webelement> views = driver.findelements(by.xpath("//*[@class='mini-counts']/span")); system.out.println("size = " + views.size()); string maxvalue = "maxvalue after sorting"; for(int i=2;i< views.size();i+=3){ if(views.get(i).gettext().equals(maxvalue)){ views.get(i).click(); file scrfile = ((takesscreenshot)driver).getscreenshotas(outputtype.file); fileutils.copyfile(scrfile, new file(system.getproperty("user.dir")+"\\screenshots\\"+"most_views.png")); }
you can use comparator, create comparator class like
public class viewcomparator implements comparator { @override public int compare(webelement w1, webelement w2) { // extract view count webelement , compare } }
and use
collections.sort(views, new viewcountcomparator());
this sort list based on view count , can take first/last webelement min/max value.
Comments
Post a Comment