0

This is my first post for help. Please correct me if you see anything wrong with my post.

I am trying to validate the sorting functionality in a web page with Selenium script (using java). here are the details...

First I go to a User search results page with multiple pages. It has users with the details: user name, number of miles. There is a sort filter drop down with values: Values A-Z, Values Z-A, Miles Most, Miles Least, Newest Members, Oldest members . by default the sorting is newest members. Initially I just want to validate: Values A-Z, Values Z-A, Miles Most and Miles Least Since I could see those values in the search page.

3
  • 1
    I am not aware of selenium. But I don't see any question here :) Commented Jun 27, 2014 at 17:01
  • there are many options, I personally would use a TreeSet Commented Jun 27, 2014 at 18:49
  • You need to provide some code. See How to Ask. Commented Jun 27, 2014 at 19:49

1 Answer 1

1

For someone who is looking to solve the same problem. Below code worked for me in validating the sorting of all the string values in a page

       //Declare Variables

            int eleCount;
            List<String> customerNameA = new ArrayList();
            List<String> customerNameB = new ArrayList();


            // Check for our Customer elements and count them.... replace xxx with your xpath
            assertTrue(isElementPresent(By.xpath("xxx")));
            elements = driver.findElements(By.xpath("xxx']"));

            eleCount = elements.size();   
            System.out.println("Element count: " + eleCount);

            for(int i = 2; i < eleCount; i++){ 
                //Capture the customer name values
                //replace xxx with your xpath & replace the value increments for each element in xpath with + i + 

                customerNameA.add(driver.findElement(By.xpath("xxx")).getText());
                System.out.println(driver.findElement(By.xpath("xxx")).getText());
                customerNameB.add(driver.findElement(By.xpath("xxx")).getText());

            }
            Collections.sort(customerNameA);   

            for (int i=0;i<customerNameA.size();i++) {
                System.out.println("Customer Name from input: " + customerNameB.get(i)  +  "--Customer Name from sorted input: " + customerNameA.get(i));
                if (!(customerNameA.get(i).equals(customerNameB.get(i)))) {
                                System.out.println("Customer Names not sorted: " + i);
                                break;

                }
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.