如何检查Selenium WebDriver中是否选择了单选按钮? [英] How to check if the radio button is selected or not in Selenium WebDriver?

查看:412
本文介绍了如何检查Selenium WebDriver中是否选择了单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的HTML代码

<div class="selectCard_left">
<input id="26110162" class="default_shipping_address" type="radio" name="address" checked="true">
<span>Seleccionar como tarjeta predeterminada</span> 

我正在尝试 driver.findElement(By.id(17390233) ))。isSelected(); ,但我没有得到任何价值。

I am trying with driver.findElement(By.id("17390233")).isSelected();, but I am not getting any value.

推荐答案

driver.findElement(By.id("26110162")).isSelected();

String str = driver.findElement(By.id("26110162")).getAttribute("checked");
if (str.equalsIgnoreCase("true"))
{
    System.out.println("Checkbox selected");
}

如果ID正在改变...
使用以下XPATH :

if the ID is changing... use the following XPATH:

//input[span='Seleccionar como tarjeta predeterminada']

//input[@name='address' and @type='radio']

这篇关于如何检查Selenium WebDriver中是否选择了单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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