【问题标题】:Select Radio Button using Robot framework使用机器人框架选择单选按钮
【发布时间】:2016-03-16 05:27:31
【问题描述】:

我有这个 HTML 代码:

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

我正在尝试使用关键字“选择单选按钮”来设置单选按钮以将值设置为“是”。

我尝试使用:

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.

【问题讨论】:

    标签: frameworks robotframework


    【解决方案1】:

    您的单选按钮没有value 或id,Select 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)单击它。

    【讨论】:

      【解决方案2】:

      选择单选按钮有时不起作用,如果要求选择单选按钮,那么“点击元素”将起作用。

      【讨论】:

        猜你喜欢
        • 2017-06-25
        • 2020-10-07
        • 2018-07-15
        • 2018-07-01
        • 2012-04-24
        • 2017-11-12
        • 2019-03-16
        • 2014-07-31
        • 2014-09-15
        相关资源
        最近更新 更多