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 in Selenium by Mohan
423 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 by Abha
• 24,440 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 in Selenium by Anvi
• 13,400 points
124 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,090 points
762 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,130 points
1,002 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,130 points
714 views
0 votes
1 answer
0 votes
1 answer