How to Handle Radio Button in Selenium Webdriver using Java

.
         Handling Radio Button in Selenium Webdriver 


In this tutorial, we are going to learn how to automate the radio button in the Selenium web driver.


How To Select Radio Button in Selenium Webdriver Using Java?

Click() 
By using the click method we select a radio button in Selenium webdriver.

Selenium Code 

// To select Radio button
driver.findElement(By.xpath("//label[@for='yesRadio']")).click();
System.out.println("Radio Button selected successfully ");


How To Verify Radio Button is Selected by default in Selenium using Java?

isSelected()
In the Selenium web driver to check whether the radio button is selected or not we use the isSelected () method.

Selenium Code 

//How to check radio button is selected or not by default
WebElement Wb=driver.findElement(By.xpath("//label[@for='yesRadio']"));
boolean ar=Wb.isSelected();
System.out.println(ar);
if(ar==false)
Wb.click();
System.out.println("Radio Button selected successfully ");


How To Verify Whether Radio Button Is Enabled or Not in Selenium using Java?

isEnable() 
To verify whether a radio button is in disable mode or enable mode we use a predefined method known as isEnable method

Selenium Code
//how to check radio button is enabled in selenium
WebElement Wb=driver.findElement(By.id("noRadio"));
boolean rs =Wb.isEnabled();
//System.out.println("Radio button is not enable");
if(rs==true)
{
Wb.click();
}


How To Verify Whether The Radio Button is Displayed or Not on a Webpage in Selenium Webdriver?

isDisplayed ()
To verify whether a radio button is displayed on the webpage or not we use the predefined method isDisplayed.

Selenium Code 

/how to verify radio button is displayed on the webpage or not
WebElement Wb=driver.findElement(By.xpath("//label[@for='yesRadio']"));
        boolean ar=Wb.isDisplayed();
        if(ar==true) {
         Wb.click();
        }


Hope!!! The above tutorial on handling the radio button in Selenium using Java is helpful for you...

Team, 
QA acharya 

Tags: Handling radio button in selenium, radio button in selenium, how to select the radio button in selenium 

How to Handle the Radio button in Selenium 


.

Post a Comment

0 Comments