I have a use case for which I have to automate the following steps:
Reverse the sorted list and return value
*** Settings ***
Library SeleniumLibrary
Library Collections
*** Keywords ***
Sort order verification
@{username_list}= Create List //creates an empty list
@{get_name}= Get WebElements css=#userTable > tbody > tr> td:nth-child(1)
:FOR ${each} IN @{get_name}
\ ${get_username}= Get Text ${each}
\ Append To List ${username_list} ${get_username} //pushes data into list in iteration
${original_order}= Copy list ${username_list} //returns original order
${sorted_list}= Sort List ${original_order} //sorts the list but returns none(nothing is saved in the variable
${reverse_sorted_list}= Reverse List ${sorted_list} //returns AttributeError: 'NoneType' object has no attribute 'reverse'
If a variable value is a list or list-like, it is also possible to use as a list variable like @{EXAMPLE}. In this case individual list items are passed in as arguments separately. The second problem is that the syntax for accessing array elements only works outside the braces if you have a single index.
The Sort List
and Reverse List
keywords modify the list in-place, e.g. they change the value of the target variable.
They also don't return anything - thus on the lines you've used them, you have assigned the value None
to the variables, which led to the error.
You can read about this behavior in the Collections library documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With