King
King

Reputation: 15

Unable to Select from drop down using visible text in RobotFramework

In Robotframework, I am able to select a value the from drop down only by using 'Select From List By Index, Select From List By Label and Select From List By Value'.

But my xml doesn't contain any Label or Value.

So, is there any keyword to like Select From List By Visible Text to select by visible text.

<select name="speed" id="speed" style="display: none;">
     <option>Slower</option>
     <option>Slow</option>
     <option selected="selected">Medium</option>
     <option>Fast</option>
     <option>Faster</option>
</select>

I found a work around like, iterating the web-list and validating the text in it and then selecting by Index

@{mylist}=    Get Webelements    //*[@id='speed']/option
${i}=    Set Variable    0
${len}=    Get Length    ${mylist}  
:FOR    ${elem}    IN    @{mylist}
\    Log To Console    ${elem}    
\    ${value}=    Get Text    ${elem}
\    Log To Console    ${value}
\    ${ival}=    Convert To String    ${i}
\    Run Keyword if    '${value}'=='Faster' or ${value}'=='Navigation Commands'
\    ...    Select From List By Index    speed    ${ival}
\    ${i}=    Evaluate    ${i}+1
\    Log To Console    ${i}      
END

But I would like to know is there any easier way to do.

Upvotes: 0

Views: 1330

Answers (1)

Todor Minakov
Todor Minakov

Reputation: 20057

The keyword Select From List By Label does what you want - selects the element by its visible text. That is, with this html:

<option>Faster</option>

, this call will select it :

Select From List By Label    id=speed    Faster

Upvotes: 2

Related Questions