• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Interview Questions
  • Java
  • Java Programs
  • Selenium
  • Selenium Programs
  • Manual Testing
  • Test Cases
  • Difference
  • Tools
  • SQL
  • Contact Us
  • Search
SoftwareTestingo » Selenium » Selenium Programs » How to Verify DropDown Values Are In Sorting Order Using Java Selenium?

How to Verify DropDown Values Are In Sorting Order Using Java Selenium?

Last Updated on: April 24, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • Verify DropDown Values Using Selenium

Verify DropDown Values Using Selenium

How to Verify Drop Down Values Are In Sorting Order Using Java Selenium?

package com.selenium.mix;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DropDownListSortedOrNot {
   @Test
   public void dropDownListSortedOrNot() throws InterruptedException {
      WebDriver driver = new FirefoxDriver();
      driver.get("http://www.ebay.in/");
      Thread.sleep(3000);  
      WebElement element = driver.findElement(By.id("gh-cat"));
      element.click();
      List<WebElement> dropDownvalues = element.findElements(By.tagName("option"));
      ArrayList<String> listValues = new ArrayList<String>();
      for(WebElement value : dropDownvalues) {
         System.out.println("values are"+ value.getText());
         listValues.add(value.getText());
      }
      boolean sortedOrNot = sortedOrNot(listValues);
      assertEquals(true, sortedOrNot);
      driver.close();

   }
   public boolean sortedOrNot(ArrayList<String> dropDownValues) {
      System.out.println("number of values "+ dropDownValues.size());
      for(int i=0; i<dropDownValues.size();i++) {
         int temp = dropDownValues.get(i).compareTo(dropDownValues.get(i+1));
         if(temp>1) {
            System.out.println("i value"+i);
            return false;
         }
      }
      return true; 
   }
}

Read Also:Get Browser Name Using JavaScriptExecutor

    Filed Under: Selenium Programs

    Reader Interactions

    Comments

    1. Avatar for SwapnaSwapna says

      May 2, 2019 at 1:55 PM

      Good to see the programs on different concepts of selenium. But some explanation in comments would help to understand the logic with more understanding

      Reply
      • Avatar for SoftwareTesting0SoftwareTesting0 says

        May 2, 2019 at 7:08 PM

        Hi Swapna, Thanks For Your suggestion we will definitely try to add them in the program for better understanding the programs.

        Reply

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Copyright © 2022 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers