
- Selenium Tutorial
- Selenium - Home
- Selenium - Overview
- Selenium - IDE
- Selenium - Environment Setup
- Selenium - Remote Control
- Selenium - Selenese Commands
- Selenium - WebDriver
- Selenium - Locators
- Selenium - User Interactions
- Selenium - Test Design Techniques
- Selenium - TestNG
- Selenium - Grid
- Selenium Useful Resources
- Selenium - Quick Guide
- Selenium - Useful Resources
- Selenium - Automation Practice
- Selenium - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Selenium - Radio Button Interaction
In this section, we will understand how to interact with Radio Buttons. We can select a radio button option using the 'click' method and unselect using the same 'click' method.
Let us understand how to interact with radio buttons using https://www.calculator.net/mortgage-payoff-calculator.html. We can also check if a radio button is selected or enabled.

Example
import java.util.concurrent.TimeUnit; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; public class webdriverdemo { public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); //Puts an Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Launch website driver.navigate().to("http://www.calculator.net/mortgage-payoff-calculator.html"); driver.manage().window().maximize(); // Click on Radio Button driver.findElement(By.id("cpayoff1")).click(); System.out.println("The Output of the IsSelected " + driver.findElement(By.id("cpayoff1")).isSelected()); System.out.println("The Output of the IsEnabled " + driver.findElement(By.id("cpayoff1")).isEnabled()); System.out.println("The Output of the IsDisplayed " + driver.findElement(By.id("cpayoff1")).isDisplayed()); //Close the Browser. driver.close(); } }
Output
Upon execution, the radio button is selected and the output of the commands are displayed in the console.

selenium_user_interactions.htm
Advertisements