0

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

asked Feb 18, 2017 at 6:43

1 Answer 1

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);
cell.setCellValue("true");
FileOutputStream fos = new FileOutputStream(new File(excelFile_Path));
workbook.write(fos);
fis.close();
fos.close();
workbook.close();
answered Feb 20, 2017 at 7:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.