I am keeping my data in excel file and read the data from there, because of avoid hard code..


public void fielding(String field,String dist,String velo,String diff) {

public void popOuttop2(String field,String dist,String velo,String diff) {


public class BaseBallEventSteps {

    WebDriver driver;
    BaseBallOutEvents baseOut;
    public BaseBallEventSteps() {
        baseOut = new BaseBallOutEvents(driver);
        baseOut=  PageFactory.initElements(DriverManager.driver, BaseBallOutEvents.class);

    public void firstInningTopOut1(String field,String dist,String velo,String diff) throws InterruptedException 
        baseOut.popOuttop2(field, dist, velo, diff);

Main method

public static void main(String[] args) throws InterruptedException, IOException {

 DriverManager manager=new DriverManager();

 BaseBallEventSteps bs=new BaseBallEventSteps();

 File f= new File("Player_names.xlsx");
 FileInputStream fs= new FileInputStream(f);
 XSSFWorkbook wb= new XSSFWorkbook(fs); 
 XSSFSheet bb_players=  wb.getSheet("Sheet2");
 int rowcount= bb_players.getLastRowNum();

 String field =  bb_players.getRow(1).getCell(1).getStringCellValue();
 String dist= bb_players.getRow(1).getCell(2).getStringCellValue();
 String velo=bb_players.getRow(1).getCell(3).getStringCellValue();
 String diff=bb_players.getRow(1).getCell(4).getStringCellValue();


enter image description here

I want to know that I am doing correct or not ? My data from excel is not reading in the main class... Error :

Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell

every time that i need to write the same String field = bb_players.getRow(1).getCell(1).toString(); to read the value from each cell.. but the length of the code should be more and is that every one following ?

Anybody please review my code , that i am doing correct or not, i can go further ?

  • For what it's worth, this is one reason I keep my locators inside the page object classes themselves - they are the only classes that need to know the locators, why add another layer of complexity in having to read in tables from other files? Jun 7 '18 at 14:54

For me the problem seems to be in the type of the values you are trying to use. The cell probably contains a number type and you are expecting a String in your code. I would suggest one of the following:

  • change the excel cell's type to text
  • instead of getStringCellValue() try getIntegerCellValue() or a similar method
  • use the toString() method
  • thanks for the support, that toString works fine for me... but let me know that I am doing correct or not..any changes should I need for my code improvement or i can go further ?
    – user32519
    Jun 8 '18 at 4:46
  • 1
    you're welcome :) you know, code improvement depends on the size and duration of the project. If this is just a random homework or a two weeks project, nobody cares so much about the code quality. But if you'll working on this for 2 years, I suggest to be as modular as you can, to separate many things in wrapping classes. Good luck, man!
    – MMMM
    Jun 8 '18 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy