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
5,075 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,930 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,110 points
3,639 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
• 58,130 points
410 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,930 points
3,841 views
0 votes
2 answers

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,520 points
3,780 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,762 views
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,890 points
2,740 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,107 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,930 points
12,671 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,930 points
3,042 views