0
votes

I am trying to choose a option by Robot Framework native Keyword "Select From List" command, however it is failed with error message :

html page source:

<select id="reason" placeholder="Please select" style="width: 100%; display: none;" class="m-b-xs" data-role="combobox" aria-disabled="false" aria-readonly="false">
<option value="a">Assume</option>
<option value="b">New</option>
<option value="c">Renew</option>
<option value="d">Purchase</option>
<option value="e">Refinance</option>
<option value="f">Reschedul</option>
<option selected="selected" value="New">New</option>
</select>

I used value "Assume" or "a":

Choose Application Reason
    Select From List    xpath=//select[@id="reason"]    Assume

Test was failed with error message:

INFO : Selecting option(s) 'Assume' from list
'xpath=//select[@id="reason"]'.  
.....
FAIL :ValueError: Option 'Assume' not in list 'xpath=//select[@id="reason"]'.
INFO : Selecting option(s) 'a' from list 'xpath=//select[@id="reason"]'.
.....
FAIL : ValueError: Option 'a' not in list 'xpath=//select[@id="reason"]'.

But if I replace value "Assume" with default vale "New":

Choose Application Reason
    Select From List    xpath=//select[@id="reason"]    New

test was passed.

Can anyone do the help? Thanks ahead.

6

6 Answers

5
votes

I had similar issues with select drop downs and i tried this and worked for me.

click element   xpath=//select[@id="reason"]
wait until element is visible   xpath=//option[contains(text(),'${label}')]
click element   xpath=//option[contains(text(),'${label}')]

If you want to select any static value form the list.

click element   xpath=//select[@id="reason"]
click element   xpath=//select/option[0]

You can also use text equal,

click element   xpath=//option[text()='${label}')]

To ignore blank,

click element   xpath=//option[normalize-space(text())='Assume']
1
votes

I guess it worked as New is a default option. For me keyword "Select from List by Value" works better. Try:

Select From List by Value    xpath=//select[@id="reason"]    a

If it doesn't work - I used to have an error with an element state - add Click Element before selecting from list:

Click Element    xpath=//select[@id="reason"]
Select From List by Value    xpath=//select[@id="reason"]    a
0
votes

should use Label, which means text

e.g.

Select From List By Label   xpath=//select[@id="reason"]    Assume
0
votes

Other alternative by using Index

Select From List By Index    xpath=//select[@id="reason"]    1
0
votes

I think you should select by value :

select from list by value       xpath=//select[@id="reason"]     a
0
votes

when you want to value a, I solved the problem this way.

***Keywords***

Select By Value

   [Arguments]    ${locator}    ${value}

   Page Should Contain Element    ${locator}  10

   Select From List By Value      ${locator}  ${value}

   List Selection Should Be       ${locator}  ${value}

Active time,

***Test Case ***

Choose Application Reason
    Select By Value  reason  a