Select 使用 Robot 框架的单选按钮

Select Radio Button using Robot framework

我有这个 HTML 代码:

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

我正在尝试使用关键字 "Select Radio Button" 设置单选按钮以将值设置为 "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.

您的单选按钮没有 valueid,这是 Select Radio Button 知道您希望它单击哪个单选按钮所必需的。您的 name=selFundDetails 仅告诉关键字您的目标群体。

来自Selenium2LibraryDocs:

Select Radio Button

Sets selection of radio button group identified by group_name to value.

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

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')]

Examples:

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)单击它。

select单选按钮有时不起作用,如果要求是select单选按钮,那么"click element "就可以。