Operations on Checkboxes and Radio Buttons are easy to perform and most of the times the simple IDattributes work fine for both of these. But selection and d-selection is not the only thing we want with checkboxes and radio buttons. We might like to check that if the checkbox is already checked or if the radio button is selected by default or anything. Checkboxes and Radio button deals exactly the same way and you can perform below mentioned operations on either of them.
Different Selection Method
By ‘ID’
If ID is given for the radio button/checkbox and you just want to click the radio button/checkbox Irrespective of its value, then the command will be like this:
With ‘IsSelected’
If your choice is based on the pre-selection of the Radio button/Checkbox and you just need to select the deselected radio button/checkbox. Assume there are two radio buttons/checkboxes, one is selected by default and you want to select the other one for your test. With IsSelected statement, you can get to know that the radio button or the check box is selected or not.
Note: Name is always same for the same group of radio buttons/checkboxes but their Values are different. So if you find the checkbox/radio button element with the name attribute then it means that it may contain more than one element, hence we need to use findElements method and store it the list of WebElements.
With ‘Value’
You can even select Radio buttons/Checkboxes with their Values.
By ‘CssSelector’
A simple way of selecting a check-box or radio button is by using its value:
Practice Exercise
1) Launch new Browser 2) Open “http://www.toolsqa.com/automation-practice-form/” 3) Select the deselected Radio button (female) for category Sex (Use IsSelected method) 4) Select the Third radio button for category ‘Years of Exp’ (Use Id attribute to select Radio button) 5) Check the checkbox ‘Automation Tester’ for category ‘Profession'( Use Value attribute to match the selection) 6) Check the checkbox ‘Selenium IDE’ for category ‘Automation Tool’ (Use cssSelector)
Great effort..Good post about selenium webdriver.It was really informative..Thanks you..keep update.check it also selenium training in chennai
ReplyDeleteselenium training in velachery
best selenium training in chennai