Handling Radio buttons
In this section, you will learn how to handle radio buttons in selenium web driver.
Following are the steps to handle the radio buttons:
Step 1: Invoke the Google Chrome browser.
The code to invoke a Google chrome browser is given below:
Step 2: The second step is to navigate to the website in which we need to handle the radio buttons.
I created the html file which contains the radio buttons. The code is given below:
The code for navigating to the above html file is given below:
The output of the above code:
Step 3: Select the option Banana. We will locate the Banana radio button by inspecting its HTML codes.
There are two ways of handling the radio buttons:
The code shown below handles the radio button by using the customized path.
In the above, we use custom Xpath. Radio buttons contain a unique attribute, i.e., value, so we use the value attribute to handle the radio button.
In the above code, we use 'for' loop. Inside the 'for' loop, we find the third radio button of group1 by using the get(2) method.