How to verify multiple checkboxes in a webpage using selenium
How to verify single checkbox in a webpage using selenium?
TestSteps
- Open the Firefox browser
- Navigate the AppUrl
- Identify Checkbox1
- Select Checkbox1
- Verify Checkbox1
- Close the current Browser window
Selenium Code : --------------------
package seleniumProject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class VerifyCheckbox { public static void main(String[] args) {
//open the firefox browser
WebDriver Driver = new FirefoxDriver();
//navigate the AppUrl
Driver.get("http://demo.guru99.com/test/radio.html");
// Identify Checkbox1 WebElement CheckBox1= Driver.findElement(By.id("vfb-6-0"));
//Select Checkbox1 CheckBox1.click();
//Verify Checkbox1
if (CheckBox1.isSelected()) { System.out.println("Checkbox1 Selected"); } else { System.out.println("Checkbox1 not Selected"); }
//Close the current Browser window
Driver.close(); } }
How to verify multiple checkboxes in a webpage using sselenium?
TestSteps :
- Open the firefox browser
- Navigate the AppUrl
- Identify all Checkboxes and store into checkBoxes variable
- Print the total checkboxes
- Select multiple checkboxes one by one
- Verify multiple checkboxes one by one
- Close the current Browser window
Selenium Code : --------------------
package seleniumProject;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Verify_Multiple_Checkboxes {
public static void main(String[] args) {
//open the firefox browser
WebDriver driver = new FirefoxDriver();
//navigate the AppUrl
driver.get("http://demo.guru99.com/test/radio.html")
// Identify all Checkboxes and store into checkBoxes variable
List checkBoxes = driver.findElements(By.xpath("//input[@type='checkbox']"));
//print the total checkboxes
System.out.println(checkBoxes.size()); for(int i=0; i<checkBoxes.size(); i++) {
//select multiple checkboxes one by one
checkBoxes.get(i).click();
//verify multiple checkboxes one by one
if(checkBoxes.get(i).isSelected()) { System.out.println(i+" checkBox is selected "); }else{ System.out.println(i+" checkBox is not selected "); } }
//Close the current Browser window
driver.close(); } }
SELENIUM | BROWSER COMMANDS :
isSelected(): By using this we can verify particular checkbox is selected or not on a webpage.
Click here: Steps to configure Selenium WebDriver with java to develop test scripts
Click here: How to handle frame in selenium webdriver using java?
Selenium Training in Hyderabad
Kosmik Technologies is on of the best selenium training in Hyderabad. We are providing lab facilities with complete real-time training. Training is based on complete advance concepts. So that you can get easily “hands-on experience”. We will give 100% job assistance.