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

use*_*483 4 selenium webdriver selenium-webdriver

<div class="my_account_module_content">
<h3 class="my_account_module_content_title">
Mi Dirección 1
<br>
<span>Predeterminada</span>

<div class="selectCard_left">
<input id="17390233" class="default_shipping_address" type="radio" name="address" checked="true">
<span>Seleccionar como tarjeta predeterminada</span>
</div>
Run Code Online (Sandbox Code Playgroud)

this is the HTML code

If radio button selected is true then print the class span value? please help me..

Ode*_*cif 5

In Java, this would do it:

if(driver.findElement(By.id("17390233")).isSelected()){
    System.out.println(driver.findElement(By.xpath("//input[@id='17390233']/following-sibling::span[1]")).getText());
}
Run Code Online (Sandbox Code Playgroud)

If the radio button is selected, then the text will show. If you want to use the text somewhere, I suggest you put it in a string instead:

String spanText = driver.findElement(By.xpath("//input[@id='17390233']/following-sibling::span[1]")).getText();
Run Code Online (Sandbox Code Playgroud)

Hope this answers your question.

EDIT: Here is an update of other ways to try.

If the className default_shipping_address is unique (e.g. not used anywhere else on the page), you may try locating the element by className:

if(driver.findElement(By.className("default_shipping_address")).isSelected()){
    System.out.println(driver.findElement(By.xpath("//input[@class='default_shipping_address']/following-sibling::span[1]")).getText());
}
Run Code Online (Sandbox Code Playgroud)

If that class is not unique, maybe the DIV's className selectCard_left is?

if(driver.findElement(By.className("selectCard_left"))){
    System.out.println(driver.findElement(By.xpath("//div[@class='selectCard_left']/span[1]")).getText());
}
Run Code Online (Sandbox Code Playgroud)

If none of the classNames are unique, a complete xpath expression is required. If you still are unable to get that text, I refer to reading up on how to use xpath: http://www.w3schools.com/XPath/xpath_syntax.asp

I hope that you find this information useful.