Select From List selects item but does not commit

2019-06-11 02:17发布

问题:

Using Robot Framework, I have a dropdown with multiple options. When I use the select from list option I can see the selection become highlighted, but when the dropdown closes, the value is not changed.

Here is a sample of my code:

click element  id=month
select from list  xpath=//select/@name="month"  September
click button  css=button.submit

I have tried variants of this with the select from list by label and select from list by value, and they fail with error stating the selected list or value does not exist.

Select from list by value example:

click element  id=month
select from list by value  xpath=//select/@name="month"  September
click button  css=button.submit

Select from list by label example 1:

click element  id=month
select from list by label  xpath=//select/@name="month"  September
click button  css=button.submit

Select from list by label example 2:

click element  id=month
select from list by label  xpath=//select/@name="month"  label=September
click button  css=button.submit

Anyone experienced this before where an item gets "selected" but the value does not get changed?

回答1:

Use following keyword.

Pass locator as 1st argument and value as another argument

Select from list by label and validate
    [Arguments]    ${locator}      ${select value}
    Focus   ${locator}
    # Select from list by label 
    Select From List By Label   ${locator}  ${select value}
    # Get selected value and validate it against passed value as argument
    ${value} =  Get Selected List Label ${locator}
    Should be equal ${select value} ${value}