0
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();
    driver.get("https://tlcs.ets.org/clientservices/profile/createAcct/createAcct.do");
    WebElement element = driver.findElement(By.id("inst_state"));
        Select s = new Select(element);
        List <WebElement> elementcount = s.getOptions();
        System.out.println(elementcount.size());
        for(int i=0 ;i<elementcount.size();i++)
        {
            String value = elementcount.get(i).getText();
            System.out.println(value);
                }
    }

}

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. – Suman Verma Mar 5 '16 at 6:56
0

With JDK 8 you can use the following solution:

List<String> labels = elementcount.stream()
  .map(WebElement::getText).collect(Collectors.toList());
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.