How to pass value of checkbox from excel file and change its status accordingly(as passed in excel) using selenium webdriver

In my case, my webpage contain some input field and 1 checkbox. I need to create entry into that form for which I am passing data using dataprovider. Now I want to know what value to be pass for checkbox in excel(True/False??) and how to handle it in method to check its existing status and change it according to as passed in excel

1 Answer 1


In selenium you can check if the specific checkbox is ticked or not by using the below code:

WebElement webelement  = driver.findElement(By.id("checkbox_id");
Boolean checkboxStatus = element.isSelected();

Note: isSelected() method returns true or false based on wheather the checkbox is ticked or not respectively.

To write the checkbox Status in the excel you will need to use Apache POI jar. Apache POI is a popular API that allows programmers to create, modify, and display MS Office files using Java programs.

Below is the code to update an existing Excel File:

String excelFile_Path = "C:\\Users\\xyz\\Desktop\\test.xlsx" ;
FileInputStream fis   = new FileInputStream(new File(excelFile_Path));
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
Cell cell = = sheet.getRow(0).getCell(0);
FileOutputStream fos = new FileOutputStream(new File(excelFile_Path));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.