I have data in Excel but when I run the code output in decimal but my excel cell format in Text
1.23456789E8
28.5
Also, how do I select radio button base on test data from excel sheet means select female button if cell data is female.
Also how to select data from the drop-down menu. Attached image with Link for Excel file
//ReadExcelShe
package excelpoi;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcelShe {
public Sheet readExcel(String filePath,String fileName,String sheetName) throws IOException {
//Create a object of File class to open xlsx file
File file = new File(filePath+"\\"+fileName);
//Create an object of FileInputStream class to read excel file
FileInputStream inputStream = new FileInputStream(file);
Workbook wb = new XSSFWorkbook(inputStream);
Sheet she = wb.getSheet(sheetName);
return she;
}
}
// googletestppo
package testpoi;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import excelpoi.ReadExcelShe;
public class googletestppo {
// TODO Auto-generated method stub
WebDriver driver;
@Test(dataProvider = "testdata")
public void login(String firstn, String lastn, String usern, String passw, String regusern, String password, String month, String day, String year) throws InterruptedException {
driver = new ChromeDriver();
driver.get("http://facebook.com/");
driver.findElement(By.name("firstname")).sendKeys(firstn);
///amidfdsds
driver.findElement(By.name("firstname")).sendKeys(lastn);
///sfasfasbad
driver.findElement(By.name("reg_email__")).sendKeys(usern);
//dsasfzxv@gmail.com
driver.findElement(By.name("reg_email_confirmation__")).sendKeys(regusern);
//dsasfzxv@gmail.com
driver.findElement(By.name("reg_passwd__")).sendKeys(password);
//1234567890 // this output come in decimal
WebElement maleRadioBtn = driver.findElement(By.id("u_0_a"));
maleRadioBtn.click();
WebElement femaleRadioBtn = driver.findElement(By.id("u_0_9"));
femaleRadioBtn.click();
Select dropdown = new Select(driver.findElement(By.id("month")));
dropdown.selectByVisibleText(month);
//Oct
Select dropdown1 = new Select(driver.findElement(By.id("day")));
dropdown1.selectByVisibleText(day);
//29 this come in decimal
Select dropdown2 = new Select(driver.findElement(By.id("year")));
dropdown2.selectByVisibleText(year);
// 1985 this come in decimal
driver.findElement(By.name("websubmit")).click();
}
@DataProvider(name = "testdata")
public String[][] readExcel() throws IOException {
ReadExcelShe file = new ReadExcelShe();
org.apache.poi.ss.usermodel.Sheet she = file.readExcel(System.getProperty("user.dir") + "\\", "DDF.xlsx", "Sheet2");
int rowCount = she.getLastRowNum();
int columnCount = she.getRow(0).getPhysicalNumberOfCells();
String[][] inputdata = new String[rowCount][columnCount];
for (int i = 0; i < rowCount; i++) {
Row row = she.getRow(i + 1);
for (int j = 0; j < columnCount; j++) {
inputdata[i][j] = row.getCell(j).toString();
System.out.println(inputdata[i][j]);
}
}
return inputdata;
}
}