Once we click on sort button, columns will sort the items in such a way that blank item will be at top and then the alphabetical order will start from A-z, for numbers it will be numeric sorting.
According to your screen, you have a change in the symbol of the sorted columns, so you should verify if it has an attribute in this case (for example sort with a ‘up’ or ‘down’, ‘asc’ or ‘desc’ value).
Then you could get info depending of the columns names and click until the attribute is as expected.
Something like this:
Table Sort
[Arguments] ${col_name} ${sort_type}
VAR ${isSorted} ${EMPTY}
WHILE '${isSorted}' != '${sort_type}'
Click Element //div[@sort and text()='${col_name}']
${isSorted} Get Element Attribute //div[@sort and text()='${col_name}'] sort
END
Of course check the structure of the table and exact xpath you can use.
Do these sortamountupalticon change to sortamountdownalticon when you change the sort direction? That would be my guess, if so apply that to @CharlieScene’s example.
sortamountupalticon
sortamountdownalticon
sort amount up alt icon
sort amount down alt icon
I also need to check if elements present in first page for each columns are sorted or not, I need to do sorting with actual elements present in the cells for each element in the first page, when we click on sort the first few sorted elements comes as blank and the rest will start alphabetically from A to Z, can you also help in validating this.
@dominique I think that you can use the following code. The keyword takes 2 embedded keywords: the visible name of the column and the sort order (Ascending / Descending).
sorttest
New Browser headless=False
New Context
New Page url=Haven't the faintest idea
Sort Column "FI Name" By "Descending" Order
Sleep 5s
*** Keywords ***
Sort Column "${column_name}" By "${sort_order}" Order
[Arguments] ${occurrence}=1
${sort_order} Convert To Lowercase ${sort_order}
IF "${sort_order}" == "ascending"
VAR ${sort_icon} sortamountupalticon
END
IF "${sort_order}" == "descending"
VAR ${sort_icon} sortamountdownicon
END
${sorted} Get Element States
... :nth-match(th[role="columnheader"]:has-text("${column_name}"):visible,${occurrence}):has(${sort_icon})
... then
... bool(value & visible)
WHILE ${sorted} == ${False}
Click :nth-match(th[role="columnheader"]:has-text("${column_name}"):visible,${occurrence})
Log To Console Matching= :nth-match(th[role="columnheader"]:has-text("${column_name}"):visible,${occurrence}):has(${sort_icon})
${sorted} Get Element States
... :nth-match(th[role="columnheader"]:has-text("${column_name}"):visible,${occurrence}):has(${sort_icon})
... then
... bool(value & visible)
END