1

Using Robot Framework, I am trying to create a loop in which a value is selected from the 1st drop-down, then a value is selected from the 2nd drop-down. The user then performs another option and then loop starts over and repeats until all elements from the 1st loop have been selected.

Currently, my code iterates completely through the 1st drop-down and then completely thru the 2nd drop-down and ends with the last value of both drop-downs selected. I need to be able to iterate through each drop-down one at a time. I have included my code & the relevant HTML.

${one}=     Get List Items      id=CMB_CLASS_ID     //get all values from 1st drop down
:FOR    ${each}     IN  @{one}
\   Select From List By Label   id=CMB_CLASS_ID     ${each}
${two}=     Get List Items      id=CMB_EVENT_TYPE_ID    //get all values from 2nd drop down
:FOR    ${each}     IN  @{two}
\   Select From List By Label   id=CMB_EVENT_TYPE_ID    ${each}

<select name="CMB_CLASS_ID" id="CMB_CLASS_ID" onchange="GetClassData();" class="form-control" orgvalue="-1" tabindex="1">
    <option value="-1" master_value="" selected="true">- Not Selected -</option>
    <option value="807000000" master_value="">Budget Lines</option>
    <option value="712000000" master_value="">Documents</option>
</select>
<select name="CMB_EVENT_TYPE_ID" id="CMB_EVENT_TYPE_ID" xml_name="EVENT_TYPE_ID" onchange="GetEventData(this);" class="form-control" orgvalue="-1" tabindex="2">
    <option value="-1" master_value="" selected="true">- Not Selected -</option>
    <option value="905000000" master_value="">Created</option>
    <option value="906000000" master_value="">Updated</option>
</select>

3 Answers 3

2
ForInZip Iteration Example
    ${one}=     Get List Items      id=CMB_CLASS_ID
    ${two}=     Get List Items      id=CMB_EVENT_TYPE_ID

    : FOR    ${each1}  ${each2}    IN ZIP    ${one}    ${two}
    \   Select From List By Label   id=CMB_CLASS_ID     ${each1}
    \   Select From List By Label   id=CMB_EVENT_TYPE_ID    ${each2}

Note: This was introduced in 2.9 version of RobotFramework, so make sure your version is equal to or greater than 2.9

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Why don't you try to put a condition that if your desired element from the list is selected, then come out of the loop instead of iterating through an entire loop? As per the code, you have mentioned here, definitely, it will traverse through the entire list elements, it selects one element and when it goes to the second element it selects that. And this process continues till the last element.

Comments

0

Another Solution is Keep second loop as a Keyword and call from first loop as below:

${one}=     Get List Items      id=CMB_CLASS_ID     //get all values from 1st drop down
:FOR    ${each}     IN  @{one}
\   Select From List By Label   id=CMB_CLASS_ID     ${each}
\   ${two}=     Get List Items      id=CMB_EVENT_TYPE_ID    //get all values from 2nd drop down
\   SelectFromSecondDropdown ${two}


****Keywords********
SelectFromSecondDropdown 
[Argument]  ${two}
:FOR    ${each}     IN  @{two}
\   Select From List By Label   id=CMB_EVENT_TYPE_ID    ${each}

Hope it helps!!!

1 Comment

It will remain a loop inside loop case! not simultaneous looping of 2 arrays, am I right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.