Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

Sorting not working in Selenium webdriver

I am trying to check if the column is sorted ascending order or descending order depending order when I click the column one or twice . I am not getting correct results by my code . My code is as below . I am taking the column to check for sorting in a List and using comparetoIgnoreCase but for test data like below its failing on test_UAT_w74 and Test123 kjfksfj for ascending order And if I check in Excel for sorting , the result is same as below . How can I work on this ? Please help

Using selenium webdriver , Should I paste this column in Excel and perform the sorting in Excel and then confirm the result or what can I do ? PLease help

Danny For Image UAT
Danny for Video UAT
danny test for SDL
sami 2020 12 09 UAT HL test1
sami 2021 01 06 Jan Rel HL test 2
test_UAT_w74
Test123 kjfksfj
We are open and processing positive pay items on November 27 and December 24 – be sure to check for exceptions

public void PickAndSortWholeServicesSubjectColumn(String order, int colnum, String ColName) {
            CommunicationCenterPage CCPage = new CommunicationCenterPage();
            String FPage = CCPage.getInboxPaginationButton().getText().trim();
            List<String> colVals = new ArrayList();
            List<WebElement> rows;
            List<WebElement> cols = new ArrayList();
            int j, m, t, a;
            String pageText;
            boolean result = false;
            boolean value = false;
            boolean value1 = true;
            boolean loopthrough = true;
            do {
            rows = CCPage.getRowsListTable().findElements(By.tagName("tr"));
            for (int k = 0; k < rows.size(); k++) {
                cols = rows.get(k).findElements(By.tagName("td"));
                colVals.add(cols.get(colnum).getText().trim());
            }
            pageText = CCPage.getInboxPaginationButton().getText().trim();
                if (CCPage.getInboxNextButton().isEnabled()) {
                    CCPage.getInboxNextButton().click();
                    this.waitForPageToLoad();
                    pauseExecutionMilliseconds(1000);
                    if (CCPage.getInboxPaginationButton().getText().trim().equals(FPage)) {
                        break;
                    }
                } else {
                    break;
                }
            rows.clear();
            cols.clear();
            } while (loopthrough);

        Reporter.log("The " + ColName + " column  captured in the list when it is in " + order + " order");
            for (int z = 0; z < colVals.size(); z++) {
                t = z;
                a = t + 1;
                Reporter.log(colVals.get(z) + " on row number " + a);

            }

        if (order.equals("descending")) {
                for (int s = 0; s < colVals.size(); s++) {
                    j = s;
                    m = j + 1;
                    if (m == colVals.size()) {
                        break;
                    }
                    if ((colVals.get(s).compareToIgnoreCase(colVals.get(m)) > 0) || (colVals.get(s).compareToIgnoreCase(colVals.get(m)) == 0)) {
                        value = true;
                    } else {
                        Reporter.log("Element on the index " + s + " which is " + colVals.get(s) + " is less than element on index " + m + " and the element is  " + colVals.get(m), MessageTypes.Fail);
                        value = false;
                        value1 = false;
                    }

                }
            } else {

                for (int s = 0; s < colVals.size(); s++) {
                    j = s;
                    m = j + 1;
                    if (m == colVals.size()) {
                        break;
                    }
                    if ((colVals.get(s).compareToIgnoreCase(colVals.get(m)) < 0) || (colVals.get(s).compareToIgnoreCase(colVals.get(m)) == 0)) {
                        value = true;
                    } else {
                        Reporter.log("Element on the index " + s + " which is " + colVals.get(s) + " is greater than element on index " + m + " and the element is  " + colVals.get(m), MessageTypes.Fail);
                        value = false;
                        value1 = false;
                    }

                }


            }
        if (value && value1) {
            result = true;
            Reporter.log("*****************************************************************************************************");
            Reporter.log("
" + " Sorting is shown correct in " + order + " order  for column " + ColName, MessageTypes.Pass);

        }

        


    }
question from:https://stackoverflow.com/questions/65928871/sorting-not-working-in-selenium-webdriver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...