import java.util.Collections;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class tlcs {

    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
    WebElement element = driver.findElement(By.id("inst_state"));
        Select s = new Select(element);
        List <WebElement> elementcount = s.getOptions();
        for(int i=0 ;i<elementcount.size();i++)
            String value = elementcount.get(i).getText();


In above code i want to check the output value is sorted or not, using comparator.Any suggestion

  • Numeric sort or string sort?
    – user246
    Mar 1 '16 at 16:19
  • in ascending order, string sort. Mar 5 '16 at 6:56

With JDK 8 you can use the following solution:

List<String> labels = elementcount.stream()
SortedSet<String> sorted = new TreeSet<>(labels); 
assertThat(labels, contains(sorted));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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