In this post we are going to learn about how to test checkboxes and radio buttons using selenium.Before jumping into that
let us see how the html code for checkbox and radio button looks like.
HTML For Checkbox
<input type=”checkbox”>
HTML For Radio Button
<input type=”radio”>
The main difference between radio button and checkbox is checkbox you can select multiple but for radio button, only one selection is possible.
we can perform click action using selenium click() method but before that it is very important to verify / test some conditions listed below-
let us see how the html code for checkbox and radio button looks like.
HTML For Checkbox
<input type=”checkbox”>
HTML For Radio Button
<input type=”radio”>
The main difference between radio button and checkbox is checkbox you can select multiple but for radio button, only one selection is possible.
we can perform click action using selenium click() method but before that it is very important to verify / test some conditions listed below-
- isEnabled()-You need to verify whether radio button or checkbox is enabled.
- isDisplayed()-You need to verify whether radio button or checkbox is Displayed on UI or not.
- isSelected()-You need to verify whether checkbox and radio button is default selected or not.
import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class RadioButtonTest { WebDriver driver; @Test public void test() throws Exception { System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe"); WebDriver driver=new ChromeDriver(); driver.manage().window().maximize(); driver.get("http://www.facebook.com"); WebElement female_radio_button=driver.findElement(By.id("u_0_b")); boolean status=female_radio_button.isDisplayed(); System.out.println("Female radio button is Displayed >>"+status); boolean enabled_status=female_radio_button.isEnabled(); System.out.println("Female radio button is Enabled >>"+enabled_status); boolean selected_status=female_radio_button.isSelected(); System.out.println("Female radio button is Selected >>"+selected_status); female_radio_button.click(); boolean selected_status_new=female_radio_button.isSelected(); System.out.println("Female radio button is Selected >>"+selected_status_new); driver.quit(); } }
You can practice with same code for chekboxes. Do try and share your feedback, suggestions and questions in the comment section below.
I am happy to find this post Very useful for me, as it contains lot of information
ReplyDeleteSelenium Course in Chennai
Selenium Training Institute in Chennai
Webtrackker is the largest training partner in Salesforce.com .Webtrackker develops and offers sales force training for end users, customer support and marketing, as well as managers, developers and consultants.
ReplyDeleteSalesforce training institute in Noida, Salesforce training in Noida
I like all the Information's are placed Here...It's Good to see all in One Resource...Thanks for this opportunity
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery