使用Robot框架选择单选按钮 [英] Select Radio Button using Robot framework
问题描述
我有以下HTML代码:
I have this HTML code:
<td><input name="selFundDetails" type="radio"></td>
我正在尝试使用关键字选择单选按钮"将单选按钮设置为是".
I am trying to set the radio button using the keyword "Select Radio Button" to set the value to "Yes".
我尝试使用:
Select Radio Button selFundDetails Yes
我收到以下错误消息:
20160316 16:17:38.216 : INFO : Verifying element 'selFundDetails' is visible.
20160316 16:17:38.362 : INFO : Selecting 'true' from radio button 'selFundDetails'.
20160316 16:17:38.667 : FAIL : ValueError: Element locator 'xpath=//input[@type='radio' and @name='selFundDetails' and (@value='true' or @id='true')]' did not match any elements.
推荐答案
您的单选按钮没有value
或id
,这是Select Radio Button
知道要单击哪个单选按钮所必需的.您的name=selFundDetails
仅告诉关键字您要定位的组.
Your radio button doesn't have a value
or id
, which is required for Select Radio Button
to know which radio button you want it to click. Your name=selFundDetails
only tells the keyword which group you are targeting.
选择单选按钮
Select Radio Button
将由group_name标识的单选按钮组的选择设置为value.
Sets selection of radio button group identified by group_name to value.
要选择的单选按钮位于两个参数中:
group_name
用作单选输入的名称,
value
用于值属性或id属性
The radio button to be selected is located by two arguments:
group_name
is used as the name of the radio input,
value
is used for the value attribute or for the id attribute
用于定位正确单选按钮的XPath如下所示://input[@type='radio' and @name='group_name' and (@value='value' or @id='value')]
The XPath used to locate the correct radio button then looks like this: //input[@type='radio' and @name='group_name' and (@value='value' or @id='value')]
示例:
Select Radio Button size XL # Matches HTML like <input type="radio" name="size" value="XL">XL</input>
Select Radio Button size sizeXL # Matches HTML like <input type="radio" name="size" value="XL" id="sizeXL">XL</input>
如果您控制html,则可以在单选按钮中添加value="Yes"
属性,您的关键字就可以使用.
If you control the html, then you can add a value="Yes"
attribute to your radio button and your keyword will work.
如果您不控制html,请上帝帮助您.但是您应该可以使用纯Click Element
(通过xpath)单击它.
If you do not control the html, god help you. But you should be able to click it with a pure Click Element
(by xpath).
这篇关于使用Robot框架选择单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!