分页时的价格排序 [英] Sorting price along with pagination

查看:105
本文介绍了分页时的价格排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要对价格进行排序的所有页面总共有97页,对当前页面的价格进行排序之后,需要单击下一步",同样需要做,直到下一步"按钮不可见为止,因为我已经编写了脚本,但我错了输出如果价格从9.00卢比提高到10.00卢比,或从99.00卢比提高到100.00卢比,或者类似的东西.
请查看下面的脚本并帮助我解决问题

I have total 97 pages for all the pages I have to sort the price and after sorting price for current page need to click on Next same need to do till Next button invisible, for that I have written script but I am getting wrong output if price increasing Rs9.00 to Rs10.00 or Rs99.00 to Rs100.00 or something like this.
Please review below script and help me to solve it

public class SortingItems extends WebDriverCommonLib
{
Select select;
@Test
public void pagination() throws InterruptedException

{       
Driver.driver.get("http://....");
Driver.driver.manage().window().maximize();
Driver.driver.findElement(By.id("auth_Username")).sendKeys("Test");
Driver.driver.findElement(By.id("auth_Password")).sendKeys("Test");
Driver.driver.findElement(By.xpath("//input[@type='submit']")).click();
WebDriverWait wait = new WebDriverWait(Driver.driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='submit-form']//i[@class='fa fa-search']")));
        Driver.driver.findElement(By.xpath("//a[@class='submit-form']//i[@class='fa fa-search']")).click();
        select = new Select(Driver.driver.findElement(By.name("product-sort")));
        select.selectByVisibleText("Price - Low to High");
        Thread.sleep(1000);

        WebElement TxtBoxContent = Driver.driver.findElement(By.xpath("//html/body/form/section/div/div/div[2]/div[3]/ul/li[6]/a"));
        int number = Integer.parseInt(TxtBoxContent.getText()); 
        if(number>1)
        {   
        System.out.println("pagination exists: "+number);

        // click on pagination link
        for(int i=1; i<=number; i++)
        {
        try
        {
System.out.println("Page "+i);
            List<WebElement> price = Driver.driver.findElements(By.xpath("//span[@class='find_prices']"));
            List<String> prices = new ArrayList<String>();
            for (WebElement e : price)
            {
                prices.add(e.getText());
            }
            List<String> sortedPrices = new ArrayList<String>(prices);
            System.out.println(sortedPrices);
            Collections.sort(sortedPrices);

            // true if the prices are sorted
            System.out.println(sortedPrices.equals(prices));

        WebElement scroll = Driver.driver.findElement(By.xpath("//a[@class='next page-numbers']"));
        scroll.sendKeys(Keys.PAGE_DOWN);
        Driver.driver.findElement(By.xpath("//a[@class='next page-numbers']")).click() ;
        waitForPageToLoad();
        }
        catch(Exception e){
        e.printStackTrace();
        }
        }
        //Driver.driver.quit();
        }
        else
        {
        System.out.println("pagination not exists");
        }
        }       
        }

**Output**<br/>

存在分页:97
第1页
[4.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,5.00,6.00,6.00,6.00,6.00,6.00,6.00,6.00,6.00,6.00,6.00,7.00] br/> 是

pagination exists: 97
Page 1
[4.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 6.00, 6.00, 6.00, 6.00, 6.00, 6.00, 6.00, 6.00, 6.00, 7.00]
true

第2页
[7.00,7.00,8.00,8.00,8.00,8.00,8.00,8.00,8.00,8.00,8.00,8.00,9.00,9.00,9.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00]
false

Page 2
[7.00, 7.00, 8.00, 8.00, 8.00, 8.00, 8.00, 8.00, 8.00, 8.00, 8.00, 8.00, 9.00, 9.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00]
false

第3页
[10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00,10.00]
真的
.
.
.
. 第37页
[99.00,99.00,99.00,99.00,99.00,99.00,99.00,99.00,99.00,99.00,99.00,99.00,99.00,100.00,100.00,100.00,100.00,100.00,100.00,100.00,100.00,100.00,100.00,100.00]
错误
.
.
.
第84页
[590.00、590.00、590.00、590.00、590.00、595.00、595.00、595.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00、600.00] br/> 真实
.
.
.

Page 3
[10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00]
true
.
.
.
. Page 37
[99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 99.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00, 100.00]
false
.
.
.
Page 84
[590.00, 590.00, 590.00, 590.00, 590.00, 595.00, 595.00, 595.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00, 600.00]
true
.
.
.

推荐答案

您可能不需要集合排序来检查列表是否已排序.使用变量来存储页面上最后一个条目的值.将变量与页面上当前条目的值进行比较.如果页面上的当前条目大于或等于上一个条目,则表示您很好,否则列表将不排序.

You may not need the collection sorting to check if list is sorted. Take the variable to store the value of last entry on page. Compare the variable with the value of current entry on page. If the current entry on page is more than or equal to last entry you are good otherwise the list is not sorted.

这篇关于分页时的价格排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆