Python 3.x RobotFramework:在For循环中使用变量列表

Python 3.x RobotFramework:在For循环中使用变量列表,python-3.x,robotframework,Python 3.x,Robotframework,我面临一个问题,这可能是因为我缺乏Python知识,但我正在尝试验证下拉列表中包含的复选框。因为正在开发的web应用程序可能在不同的页面中包含几个下拉列表,所以我想创建一个关键字,只需传递div和checkbox的泛型类即可 目前,我对此事有以下关键词: Verify Container Items [Documentation] This keyword should be used on simple list items where the elements can be te

我面临一个问题,这可能是因为我缺乏Python知识,但我正在尝试验证下拉列表中包含的复选框。因为正在开发的web应用程序可能在不同的页面中包含几个下拉列表,所以我想创建一个关键字,只需传递div和checkbox的泛型类即可 目前,我对此事有以下关键词:

Verify Container Items
    [Documentation]   This keyword should be used on simple list items where the elements can be tested for redirect funtionality.
    ...               Parameters:
    ...                 closed_locator: generic class for the closed container
    ...                 opened_locator: generic class for the opened container
    ...                 locator: generic class for a given web element inside the container
    [Arguments]    ${closed_locator}      ${opened_locator}       ${item_locator}
    ${container_closed_xpath}=    Set Variable       ${closed_locator}
    ${container_opened_xpath}=    Set Variable       ${opened_locator}
    @{container_xpath}=     Create List     ${closed_locator}      ${opened_locator}
    ${container_count}=    get element count       ${container_xpath}
    ${container_names}=    Create List
    FOR    ${i}    IN RANGE    1    @{container_count} + 1
        ${element_closed}=    Set Variable       (${container_xpath[0]})[${i}]
        ${element_opened}=    Set Variable       (${container_xpath[1]})[${i}]
        ${name}=    Get Text    xpath=${element[1]}
        Append To List    ${names}    ${name}
        Click Element   ${element_closed}
            Verify Contained Items      ${item_locator}
        Click Element   ${element_opened}
    END


Verify Contained Items
    [Arguments]     ${item_locator}
    ${item_xpath}=    Set Variable       ${item_locator}
    ${item_count}=    get element count       ${item_xpath}
    ${item_names}=    Create List
    FOR    ${i}    IN RANGE    1    ${item_count} + 1
        ${element}=    Set Variable       (${item_xpath})[${i}]
        ${name}=    Get Text    xpath=${element}
        Append To List    ${item_names}    ${name}
        Click Element   ${element}
    END 
这就是我对python的了解可能会困扰我的地方。在第一个关键字中,我为关闭的下拉列表传递xpath,打开的下拉列表存储在一个列表中,该列表将用于for计数,我希望它单击关闭的下拉列表打开它,调用另一个关键字勾选所有复选框,单击打开的下拉列表将其关闭,并增加“关闭”或“打开”下拉列表的值,并使用其他下拉列表/复选框删除

但是,当运行测试时,我得到错误:

AttributeError:“list”对象没有属性“startswith”

在这一点上,我尝试了所有的方法,但我陷入了困境,我开始用其他关键字来解决问题,但我想知道是否有可能用两个变量的列表来解决问题,或者我只是在浪费时间,可能是在浪费脑细胞


顺便说一句,我正在使用SeleniumLibrary和Collections库以及PyCharm来编码

哪个关键字会给你这个错误?错误是
${container\u count}=get element count${container\u xpath}
我忘了说。我将编辑您将列表传递给
Get Element Count
的主要帖子。它需要一个定位字符串,但我是用
${container\u count}=get element count${container\u xpath}
来实现这一点的,我的问题是因为我使用的是一个列表而不是单个变量,我问我是否可以用一个列表来实现。