How to sort 6 or more columns in a grid

Because this is working for me:

Hi @falcon030,

Iā€™m using these versions:

robotframework-browser==18.4.0

robotframework-databaselibrary==1.3.1

robotframework-excellib==2.0.1

robotframework-jsonlibrary==0.5

robotframework-pabot==2.18.0

robotframework-requests==0.9.7

And the version of Robot Framework?

robot --version

Can you test if the following code is working?

*** Test Cases ***
sorttest
    New Browser     headless=False
    New Context
    New Page        url=https://primeng.org/table#single-column-sort
    Sort Column "Code" 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

@dominique And if you try this code?

*** Keywords ***
Sort Column "${column_name}" By "${sort_order}" Order
    [Arguments]         ${occurrence}=1
    VAR    ${sort_icon}    sortamountupalticon
    ${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

BTW Are you using the Robocorp VS Code extension? If so you can beter use RobotCode since the Robocorp extension has issues with Robot Framework 7.

Hi @falcon030,

I was using none of the above mentioned extensions but now just installed RobotCode, but still have the same error with $ā€œ{sortIcon}ā€

Even with this code?

*** Keywords ***
Sort Column "${column_name}" By "${sort_order}" Order
    [Arguments]         ${occurrence}=1
    VAR    ${sort_icon}    sortamountupalticon
    ${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})
        ${sorted}       Get Element States
        ...             :nth-match(th[role="columnheader"]:has-text("${column_name}"):visible,${occurrence}):has(${sort_icon})
        ...             then
        ...             bool(value & visible)
    END
2 Likes

Hi @falcon030 , this worked for me, thank you very much for the help provided, it was an issue with the extension as you said.

Dominique

1 Like