使用Robot框架选择单选按钮

时间:2016-03-16 05:27:32

标签: frameworks robotframework

我有这个HTML代码:

<td><input name="selFundDetails" type="radio"></td>

我正在尝试使用关键字&#34;选择单选按钮&#34;设置单选按钮。将值设置为&#34;是&#34;。

我尝试使用:

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.

2 个答案:

答案 0 :(得分:2)

您的单选按钮没有valueidSelect Radio Button需要知道您要点击哪个单选按钮。您的name=selFundDetails仅告知关键字您要定位的群组。

来自Selenium2LibraryDocs

  

选择单选按钮

     

将group_name标识的单选按钮组的选择设置为值。

     

要选择的单选按钮有两个参数:   group_name用作无线电输入的名称,   value用于value属性或id属性

     

用于找到正确单选按钮的XPath如下所示://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"属性,然后您的关键字就会有效。

如果你不控制html,上帝帮助你。但您应该能够使用纯Click Element(通过xpath)单击它。

答案 1 :(得分:0)

选择单选按钮有时不起作用,如果要求是选择一个单选按钮,那么&#34;单击元素&#34;会工作的。

相关问题