Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the radio button is selected or not in Selenium WebDriver?

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.

like image 789
user3538483 Avatar asked May 22 '14 07:05

user3538483


People also ask

How can you check the status of a checkbox radio button?

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.

Which method is used to select radio button in Selenium?

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.

How do you know if an element is selected in Selenium?

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.


1 Answers

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']
like image 59
HemaSundar Avatar answered Oct 16 '22 15:10

HemaSundar