Hello guys,
I have faced a problem with sorting the web elements.
This is my code:
def static getInsideRemainingPrincipalForAllGroups(String clientNO, String fieldName) {
// List<WebElements> elements = DriverFactory.getWebDriver().findElements(By.xpath("//div[@class='sc-bdVaJa sc-iwsKbI sc-fQkuQJ vSwtM']"))
def groupsFromDB = DataService.getGroups(numberNO)
KeywordUtil.logInfo("Groups from DB: " + groupsFromDB)
def myListRemainingPrincipal = []
WebUI.delay(1)
if(fieldName == 'Remaining principal') {
List<WebElements> consumerElements = DriverFactory.getWebDriver().findElements(By.xpath("//div[@class='sc-bdVaJa sc-iwsKbI sc-fQkuQJ vSwtM']"))
for(int i = 0; i < groupsFromDB.size(); i++) {
consumerElements.get(i).click()
WebUI.delay(10)
def mainRemainingPrincipal = WebUI.getText(findTestObject('Object Repository/InsidePage/div_InsideRemainingPrincipal_MainL'))
def secondaryRP = WebUI.getText(findTestObject('Object Repository/InsidePage/div_InsideRemainingPrincipal_Secondary'))
def joinedRemainingPrincipal = mainRemainingPrincipal + secondaryRP
myListRemainingPrincipal << groupsFromDB[i] + ": " + joinedRemainingPrincipal
WebUI.delay(1)
WebUI.click(findTestObject('Object Repository/InsidePage/div_Back to Page'))
WebUI.delay(4)
consumerElements = DriverFactory.getWebDriver().findElements(By.xpath("//div[@class='sc-bdVaJa sc-iwsKbI sc-fQkuQJ vSwtM']"))
consumerElements = consumerElements.sort()
}
return myListRemainingPrincipal
}
}
And this is my page:
When I click an object, I get some field text name and after that I come back on this page and trying to click next element.
Whats my problem. From Database I get sorted names like : Consumer, Consumer, Craft, Overdue. I want to sort this objects and click sorted objects, because I am printing elements with taken db name + name which i took from page: groupsFromDB[i] + ": " + joinedRemainingPrincipal.
But, the problem is, it clicks with the following iteration: Consumer, Craft, Consumer, Overdue.
I’ve also tried to write: consumerElements.sort(), but it does not work.