【问题标题】:Validating the sorting functionality using Selenium (Java)使用 Selenium (Java) 验证排序功能
【发布时间】:2014-06-27 17:01:00
【问题描述】:

这是我第一次寻求帮助。如果您发现我的帖子有任何问题,请纠正我。

我正在尝试使用 Selenium 脚本(使用 java)验证网页中的排序功能。这是详细信息...

首先,我转到包含多个页面的用户搜索结果页面。 它有用户详细信息:用户名,里程数。 有一个带有值的排序过滤器下拉列表:Values A-Z, Values Z-A, Miles Most, Miles Least, Newest Members, Oldest members 。默认情况下,排序是最新成员。 最初我只想验证:A-Z 值、Z-A 值、最多英里和最少英里,因为我可以在搜索页面中看到这些值。

【问题讨论】:

  • 我不知道硒。但我在这里没有看到任何问题:)
  • 有很多选择,我个人会用TreeSet
  • 您需要提供一些代码。见How to Ask

标签: java sorting selenium


【解决方案1】:

对于希望解决相同问题的人。下面的代码在验证页面中所有字符串值的排序方面对我有用

       //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;

                }
            }
        }

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 2022-01-04
    • 2021-03-17
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    相关资源
    最近更新 更多