[英]How to find Radio button is checked or not in Robot framework
How to find is the radio button checked or not using the robot framework如何使用机器人框架找到是否选中了单选按钮
For example:例如:
<div>
<label>Male</label>
<input name="gender" id="genderM" value="m" />
<label>Female</label>
<input name="gender" id="genderF" value="f" checked />
</div>
You can use below code to verify您可以使用以下代码进行验证
def is_checked(self, driver, item):
checked = driver.execute_script(("return document.getElementById('%s').checked") % item)
return checked
or you can use或者你可以使用
driver.find_element_by_name("< check_box_name >").is_selected()
Seems like Robots provides some built-in functionality for this -- you can use Checkbox Should Be Selected :似乎机器人为此提供了一些内置功能-您可以使用Checkbox Should Be Selected :
Checkbox Should Be Selected | locator | Verifies checkbox locator is selected/checked.
See the Locating elements section for details about the locator syntax.
You could use the Selenium RF keyword https://robotframework.org/Selenium2Library/Selenium2Library.html#Radio%20Button%20Should%20Be%20Set%20To您可以使用 Selenium RF 关键字https://robotframework.org/Selenium2Library/Selenium2Library.html#Radio%20Button%20Should%20Be%20Set%20To
Radio Button Should Be Set To group_name, value
Verifies radio button group group_name is set to value.验证单选按钮组 group_name 是否设置为值。 group_name is the name of the radio button group. group_name 是单选按钮组的名称。
Check with keyword:检查关键字:
Element Should Be Enabled | locator
This worked for me.这对我有用。 HTML looked like: HTML 看起来像:
<input class="jss816" name="visibility" type="radio" value="AdminOnly" checked="">
<input class="jss816" name="visibility" type="radio" value="Internal">
This Robot command returns 1 if this radio is checked:如果选中此无线电,则此 Robot 命令返回 1:
get element count css:input[name='visibility'][value='Internal']:checked
Not clear why this couldn't be done with an xpath, but I couldn't find a way!不清楚为什么这不能用 xpath 完成,但我找不到方法!
For Example:例如:
<div>
<label>Male</label>
<input name="gender" id="genderM" value="male" />
<label>Female</label>
<input name="gender" id="genderF" value="female" checked />
</div>
Below code is to check and select the checkbox下面的代码是检查和 select 复选框
${Status} Run Keyword And Return Status Radio Button Should Be Set To gender male
If ${Status} is True, then radio button male is checked, else radio button Female is checked.如果 ${Status} 为 True,则选中单选按钮男性,否则选中单选按钮女性。 Based on the ${Status} we can select the required radio button using below mentioned keywords.基于 ${Status} 我们可以使用下面提到的关键字 select 所需的单选按钮。
Run Keyword If '${Status}' == 'False' select radio button gender male
Run Keyword Unless '${Status}' == 'False' log Already it is selected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.