Reputation: 69
Here is html code for selected radio button
<input name="blooms_level" value="4" id="blooms_level4" class="radio " checked="" type="radio">
i tried below code, its returning null
String str = driver.findElement(By.xpath("xpathValue")).getAttribute("checked");
str.equalsIgnoreCase("true");
please suggest any alternate way since checked value is null
Upvotes: 0
Views: 1560
Reputation: 25577
You can do something simple like
Assert.assertTrue(driver.findElement(By.id("blooms_level4")).isSelected(), "Verify checkbox is checked");
with TestNG.
Upvotes: 0
Reputation: 193078
To validate if the radio button is selected or not you can use either of the following solution:
if(driver.findElement(By.xpath("//input[@class='radio' and @name='blooms_level'][starts-with(@id,'blooms_level')]")).isSelected())
//if(driver.findElement(By.cssSelector("input.radio[name='blooms_level'][id^='blooms_level']")).isSelected())
System.out.println("Radio Button is selected");
else
System.out.println("Radio Button is not selected");
Upvotes: 0
Reputation: 732
Try the Java code mentioned below:
Boolean radioSelected= driver.findElement(By.xpath("xpathValue")).isSelected();
if (radioSelected)
{
System.out.println("Radio Button is selected");
}else{
System.out.println("Radio Button is not selected");
}
Upvotes: 1