使用Robot框架选择单选按钮 [英] Select Radio Button using Robot framework

查看:240
本文介绍了使用Robot框架选择单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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.

推荐答案

您的单选按钮没有valueid,这是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.

Selenium2LibraryDocs :

选择单选按钮

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆