Quality Testing

Quality is delighting customers

How to verify radio button selected or not in Selenium WebDriver ?

<div class="col-2">
<div class="radio">
<label>
<input class="ng-valid ng-touched ng-dirty ng-valid-parse" type="radio" ng-model="dealCtrl.auctionType.value" ng-value="dealCtrl.auctionType.options.firstPrice.value" name="auctionTypeOptions" ng-change="dealCtrl.auctionType.onChange()" value="1">
<span class="label ng-binding">First Price</span>
</label>
<label>
<input class="ng-valid ng-dirty ng-touched" type="radio" ng-model="dealCtrl.auctionType.value" ng-value="dealCtrl.auctionType.options.secondPrice.value" name="auctionTypeOptions" ng-change="dealCtrl.auctionType.onChange()" value="2">
<span class="label ng-binding">Second Price</span>
</label>
</div>

Can any one please share the code. How to verify radio button selected or not in Selenium WebDriver ?

Views: 3023

Reply to This

Replies to This Discussion

Hi,
You can verify in 2 ways:

1. Directly you can use .isSelected()
eg System.out.println(driver.findElement(By.xpath("")).isSelected());
Here take the xpath or any locator for 1st radio button. This will give True or False as per the radio button is selected or not

2.
Use a common method
public static void radiobtn(WebElement element){
boolean btn = element.isSelected();
if(btn == true){
System.out.println("Radio button is Selected:"+element.getAttribute("checked"));
}else{
System.out.println("Radio button is Selected:"+element.getAttribute("checked"));
}
}
In the main script just call the method
Here it will check the boolean value as per the selected or not and enter into the loop.

IsSelected() - will work

boolean CheckboxDefaultStatus = driver.findelement(By.xpath("//span[contains(text(),'First Price')]").isSelected();

if(CheckboxDefaultStatus ==true)

{

System.out.println("First Price checkbox got selected" +"\n" +"\n");

}

else

{

System.out.println("First Price checkbox not selected" +"\n" +"\n");

}

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service