i
WebDriver Introduction
Selenium WebDriver Architecture
Introduction to WebDriver API
Introduction to WebDriver – Code
Handling Dropdowns and Select class
Handling Multiple Dropdown values and Links
Handling Radio buttons and Checkboxes
Capture Screenshots and Email test results
Browser Navigation Methods
Handling tabs
Capturing screenshot, Handling tabs and pop-ups – Code
Handling tabs and Pop-ups – Code
Handling Alerts
Handling User Authentication and Input alerts
HtmlUnitDriver and Handling Captchas
Handling Web Tables
Synchronization
Handling WebTables, Synchronization issues, Firefoxprofiles – Code
Actions Class
Event Listeners, Event Firing Mouse, Coordinates – Code
Handling Mouse Hover in Selenium
JavascriptExecutor
Handling Iframes
IsElementPresent, IsEnabled, IsSelected
Working with Chrome Driver - Part 1
Working with FireFox Driver - Part 2
Working with Internet Explorer Driver - Part 3
Handling SSL Certificate
Desired Capabilities
How to Encode password in WebDriver
Handling JQuery Elements - Drag and Drop, Sliders, Resizable
Handling JQuery Elements - Drag and Drop, Sliders, Resizable – Code
Working on IE Browser using Actions
TestNG, Ant & Report Generation through XSLT
Introduction to TestNG and Annotations
TestNG Parameterization
Configuring ANT, Generating TestNG & XSLT Reports
Code for generating XSLT / Surefire Reports through MAVEN
TestNG Parameterization Excel Reading
Handling Multiple data providers
TestNG XSLT Jar, Build.xml & TestNG.xml file
Frameworks Introduction
Hybrid (DATA + KEYWORD) driven Framework
Framework Architecture
Reading Excel sheets
TestNG DataProvider
Data Provider with Hashtable
Handling Multiple Test Suites
Multiple DataProviders
Setting up Run-modes at Suite Level
Setting up Runmodes at TestCase Level
Creating a common utility for Run-modes
Hybrid Framework Code
Radio buttons and checkboxes are similar in the selection process; the only difference between these two is that Radio button options do not have multiple select capabilities, unlike checkboxes. Let us understand how we can handle both situations in our Selenium testing problem.
We need to locate the Radio button/Checkbox element to start further operations on it. I have used a webpage on http://www.echoecho.com/htmlforms10.htm for explaining this example.
Here the first step is to locate the radio button elements using any locator like id, name, className, and XPath, etc. Once we get a universal locator for one Radio button, then we can figure out all the Radio buttons in a list of elements. This tells us the total number of radio buttons present.
List elements=driver.findElements(By.xpath("//table[3]/tbody/tr/td/table/tbody/tr/td/input[@name='group2']"));
Let us figure out the total number of radio button present using the list of elements.
int iSize=elements.size();
Once we get the number of Radio buttons, then we can select the radio button easily by checking the Radio button’s value.
for(int i=0;i
{
String btnValue=elements.get(i).getAttribute("value");
if(btnValue.equalsIgnoreCase("Water"))
{
elements.get(i).click();
}
}
Let us check the complete code to handle this situation below:
package SeleniumTest.SeleniumTest;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class RadioButtonCheckBox
{
public static void main( String[] args )
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.echoecho.com/htmlforms10.htm");
List elements=driver.findElements(By.xpath("//table[3]/tbody/tr/td/table/tbody/tr/td/input[@name='group2']"));
int iSize=elements.size();
System.out.println(iSize);
for(int i=0;i
{
String btnValue=elements.get(i).getAttribute("value");
if(btnValue.equalsIgnoreCase("Water"))
{
elements.get(i).click();
}
}
driver.quit();
}
}
Don't miss out!