[英]How to check if the radio button is selected or not in Selenium WebDriver?
Here is my HTML code这是我的 HTML 代码
<div class="selectCard_left">
<input id="26110162" class="default_shipping_address" type="radio" name="address" checked="true">
<span>Seleccionar como tarjeta predeterminada</span>
I am trying with driver.findElement(By.id("17390233")).isSelected();
我正在尝试使用driver.findElement(By.id("17390233")).isSelected();
, but I am not getting any value. ,但我没有得到任何价值。
driver.findElement(By.id("26110162")).isSelected();
or或者
String str = driver.findElement(By.id("26110162")).getAttribute("checked");
if (str.equalsIgnoreCase("true"))
{
System.out.println("Checkbox selected");
}
if the ID is changing... use the following XPATH:如果 ID 正在更改...使用以下 XPATH:
//input[span='Seleccionar como tarjeta predeterminada']
or或者
//input[@name='address' and @type='radio']
.isSelected()
function will returns you a boolean value True
or False
, depending on that you can check the condition and enable or leave the radio button selected. .isSelected()
函数将返回一个布尔值True
或False
,具体取决于您可以检查条件并启用或保持选中单选按钮。
driver.findElement(By.cssSelector("input[id='26110162']")).isSelected().
Declare a boolean value and store the result then provide an if condition to validate声明一个布尔值并存储结果,然后提供一个 if 条件来验证
You can try any of this method:-您可以尝试以下任何一种方法:-
selenium.isChecked(Locator);
List<WebElement> radio = driver.findElements(By.name("address")); radio.get(0).getAttribute("checked"));
Hope it will help...希望它会有所帮助...
Try in selenium java: 尝试selenium java:
String name = driver.findElement(By.xpath("path"));
assertEquals(name.isSelected(),true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.