我有一个用例,我必须自动执行以下步骤:
反转排序列表并返回值
*** 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'
Run Code Online (Sandbox Code Playgroud)在Sort List和Reverse List关键字修改列表就地,如他们改变目标变量的值。
它们也不返回任何内容 - 因此在您使用它们的行中,您已将值分配None给变量,这导致了错误。
您可以在Collections 库文档中阅读有关此行为的信息
| 归档时间: |
|
| 查看次数: |
4116 次 |
| 最近记录: |