Here is my HTML code
<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();
, but I am not getting any value.
You can use the dynamic find() API to verify the status of a radio button or check box during playback, such as whether the control was selected or not.
whereas using checkbox, we can select multiple options. Using Click() method in Selenium we can perform the action on the Radio button and on Checkbox. WebElement maleRadioBtn = driver.
isSelected() Method in Selenium The isSelected() method checks that if an element is selected on the web page or not. It returns a boolean value (true) if selected, else false for deselected. It can be executed only on a radio button, checkbox, and so on.
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:
//input[span='Seleccionar como tarjeta predeterminada']
or
//input[@name='address' and @type='radio']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With