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,642 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,760 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
990 views
+3 votes
1 answer

How to read excel file numeric data of all rows and column in selenium? I have 10 rows and 5 column but I read Only String value not a Numeric value?

Hey, @Mahendra, check this thread https://www.edureka.co/community/52170/read-numeric-data-from-excel-sheet-using-selenium-webdriver It deals with ...READ MORE

answered Jan 27 in Selenium by Sirajul
• 48,770 points
167 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,760 points
1,724 views
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,774 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,870 points
1,610 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,870 points
1,449 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,760 points
5,253 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,760 points
969 views