我正在尝试通过Robot Framework原生关键字选择一个选项"从列表中选择"命令,但它失败并显示错误消息:
html页面来源:
YoutubeAPI
我用了价值"假设"或" a":
<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>
测试失败,错误消息:
Choose Application Reason
Select From List xpath=//select[@id="reason"] Assume
但如果我取代价值&#34;假设&#34;使用默认值&#34;新&#34;:
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"]'.
测试通过了。
有人可以帮忙吗?谢谢你。
答案 0 :(得分:5)
我有选择下拉的类似问题,我试过这个并为我工作。
click element xpath=//select[@id="reason"]
wait until element is visible xpath=//option[contains(text(),'${label}')]
click element xpath=//option[contains(text(),'${label}')]
如果要从列表中选择任何静态值。
click element xpath=//select[@id="reason"]
click element xpath=//select/option[0]
您也可以使用文字相等,
click element xpath=//option[text()='${label}')]
要忽略空白,
click element xpath=//option[normalize-space(text())='Assume']
答案 1 :(得分:1)
我猜它有效,因为New是默认选项。 对我来说,关键字“从值按列表中选择”效果更好。 尝试:
Select From List by Value xpath=//select[@id="reason"] a
如果它不起作用 - 我曾经有一个元素状态的错误 - 在从列表中选择之前添加Click Element:
Click Element xpath=//select[@id="reason"]
Select From List by Value xpath=//select[@id="reason"] a
答案 2 :(得分:0)
应该使用Label,这意味着文本
e.g。
Select From List By Label xpath=//select[@id="reason"] Assume
答案 3 :(得分:0)
使用Index
Select From List By Index xpath=//select[@id="reason"] 1
答案 4 :(得分:0)
我认为你应该按价值选择:
select from list by value xpath=//select[@id="reason"] a
答案 5 :(得分:0)
当您想估价a
时,
我这样解决了问题。
***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}
活动时间,
***Test Case ***
Select By Value reason a