'How to check whether list is sorted or not in Robotframework

I am trying to run below code but getting below error as -: TypeError: '<' not supported between instances of 'WebElement' and 'WebElement'

${original_list} =    Get WebElements     ${accountsid}
${sorted_list}= SORT LIST    ${original_list}
click element      ${sort_button}
${after_sorting}=     Get WebElements     ${slot_Sorting_Slot_Id}
lists should be equal    ${sorted_list}    ${after_sorting}


Solution 1:[1]

Like the error message says, you cannot compare objects of type WebElements. This is because they are a block of data with an ID, that webdriver provided to the user. This data allows to reference the real HTML element on the browser.

In your test script, you need additional steps to get the real data you need to compare. Here is my proposal:

${original_list} =    Get Data    ${accountsid}
${sorted_list}= SORT LIST    ${original_list}
click element      ${sort_button}
${after_sorting}=     Get Data     ${slot_Sorting_Slot_Id}
lists should be equal    ${sorted_list}    ${after_sorting}

With Get Data like:

*** Keywords ***
Get Data
    [Arguments]    ${locator}
    Import Library    Collections    # Probably already declared globally
    @{data}=    Create List
    @{my_list}=    Get WebElements     ${locator}
    FOR    ${element}    IN    @{my_list}
        ${item}=    Get Text    ${element}
        Append To List    ${data}    ${item}
    END
    Return From Keyword    ${data}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Helio