如何在迭代中选择下拉列表中的项目

时间:2018-11-09 06:58:31

标签: for-loop robotframework

我有一个下拉列表,其中包含'n'个项目。我必须验证所有下拉项都是可单击的。要执行此操作,我使用了如下所示的for循环:

*** Settings ***
Resource  ../resources/settings.robot

*** Test Cases ***
TC title
  Make sure that the user should be able to select an item from the drop down list

*** Keywords ***
Make sure that the user should be able to select an item from the drop down list
Click Element  ${combo_box}           //Clicking on the combo box displays the drop down list
@{get_role_list}=   Get WebElements  css=td.row-highted > div:nth-child(1) > combo-box:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div
:FOR    ${each}     IN      @{get_role_list}
\  Click Element  @{get_role_list}    //selects an item from the list in an iteration
\  Click Element  ${combo_box}        //once an item from the list is selected the drop down list disappears, to iterate this loop drop down list should be displayed hence clicking on combo box after selecting an item

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

在我看来,您应该单击${each}而不是@{get_role_list}

:FOR    ${each}     IN      @{get_role_list}
\    
\    # selects an item from the list in an iteration
\    Click Element  ${each}
\  
\    # once an item from the list is selected the drop down list disappears, 
\    # to iterate this loop drop down list should be displayed hence clicking 
\    # on combo box after selecting an item
\    Click Element  ${combo_box}