How to read test data from an excel sheet and use it to test facebook login in Selenium Webdriver?

0 votes
How to read test data from an excel sheet and use it to test facebook login using Apache POI in Selenium Webdriver?
Jul 16, 2019 in Selenium by Mohan
1,351 views

1 answer to this question.

0 votes

Hi Mohan, you can use following code snippet to read test data from an excel sheet and use it to test facebook login page:

public class ReadWriteExcel
{
WebDriver driver;
WebDriverWait wait;
HSSFWorkbook workbook;
HSSFSheet sheet;
HSSFCell cell;

public void ReadData() throws IOException {

System.setProperty("webdriver.gecko.driver", "C:\\Users\\geckodriver.exe"); 

driver = new FirefoxDriver(); 

driver.get("http://www.facebook.com/"); 

driver.manage().window().maximize(); 

wait = new WebDriverWait(driver,30); 

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 

// Import excel sheet. 

File src=new File("C:\\Users\\Admin\\Desktop\\TestData.xls"); 

// Load the file. 

FileInputStream finput = new FileInputStream(src); 

// Load the workbook. 

workbook = new HSSFWorkbook(finput); 

// Load the sheet in which data is stored. 

sheet= workbook.getSheetAt(0); 

for(int i=1; i<=sheet.getLastRowNum(); i++) { 

// Import data for Email. 

cell = sheet.getRow(i).getCell(1); 

cell.setCellType(Cell.CELL_TYPE_STRING); 

driver.findElement(By.id("email")).sendKeys(cell.getStringCellValue()); 

// Import data for password. 

cell = sheet.getRow(i).getCell(2); 

cell.setCellType(Cell.CELL_TYPE_STRING); 

driver.findElement(By.id("pass")).sendKeys(cell.getStringCellValue()); 

} 

} 

}
answered Jul 17, 2019 by Abha
• 27,740 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How to create a Base Class in Selenium and use it with test scripts?

Hi Donna, you can use following code ...READ MORE

answered Jul 18, 2019 in Selenium by Anvi
• 14,010 points
754 views
+1 vote
1 answer

Is it possible to write data into an excel file using Selenium Webdriver?

Hi Simran, if you want to directly ...READ MORE

answered May 8, 2019 in Selenium by Abha
• 27,740 points
1,544 views
+1 vote
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
1,542 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,850 points
1,486 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,850 points
1,265 views
0 votes
1 answer

How can we read data from an excel sheet in Selenium webdriver?

Hi Tarun, to read data from an ...READ MORE

answered May 8, 2019 in Selenium by Abha
• 27,740 points
4,223 views
0 votes
1 answer

How can I read numeric data from an Excel sheet using Selenium Webdriver?

Hey Jignesh, for reading numeric data from ...READ MORE

answered Jul 17, 2019 in Selenium by Abha
• 27,740 points
784 views