0

how to change the number into string from excel sheet using selenium webdriver Im passing the value as 10 in excel sheet but it enter as 10.0 in web application. thanks in advance

3
  • Are you reading into a string the value from excel? Commented Oct 29, 2014 at 12:19
  • It sounds like passing into. What method are you using to set the value in the cell? Some example code would be very helpful here Commented Oct 29, 2014 at 12:35
  • im reading the text value as 10 from excel sheet.but when it enter into the webelement it type the value as 10.0. also i changed the category as text in excel. Commented Oct 29, 2014 at 12:45

2 Answers 2

1

Solution 1

I hope you are using apache poi for reading from Excel. In that case, this sample can help you

CellReference cr = new CellReference("A1");
XSSFRow row = sheet.getRow(cr.getRow());
XSSFCell cell = row.getCell(cr.getCol());
switch (cell.getCellType()) {
    case XSSFCell.CELL_TYPE_NUMERIC:
        System.out.println(cell.getRawValue());
        break;
    case XSSFCell.CELL_TYPE_BOOLEAN:
        System.out.println(cell.getBooleanCellValue());
        break;
    case XSSFCell.CELL_TYPE_STRING:
        System.out.println(cell.getStringCellValue());
        break;
    default:
        System.out.println(cell.getRawValue());
}

For value 1234 in excel cell.getNumericCellValue() will return you 1234.0 and cell.getRawValue() will return 1234

Solution 2

And in case you cant modify anything in the place where you read the Excel, format the String before entering the value using Webdriver

public static void main(String[] args) {
    String input = "1234.0";
    try {
        double parseDouble = Double.parseDouble(input);
        DecimalFormat df = new DecimalFormat("0");
        String formatNumber = df.format(parseDouble);
        System.out.println(formatNumber);
    } catch (Exception e) {
        System.out.println("Input is not a numeric");
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for sharing..i cant oddcode the input value.soo, whenever i need to change the value should b changed only in excel sheet not in program.
please see the below program @sachin
public static void inttypeIn(String objLocator, String inputValue){ try {findWebElement(objLocator); webElement.sendKeys(inputValue); webElement.sendKeys(Keys.TAB); APP_LOGS.debug("Typing '" + inputValue + "' in : locatorDescription); } catch (Exception e) { APP_LOGS.debug("FAIL : The locator "+objLocator+" of description '"+locatorDescription+"': does not exists in webpage:"); Reporting.fail("FAIL : The locator '"+objLocator+"' of description '"+locatorDescription+"': does not exists in webpage:"); }
this input value should be in string,from the excel sheet im getting the integer value, in this need to change the inputvalue into string.if i change inputvalue as integer in this method, sendkeys(inbuild java method)doesnt accept the integer inputvalue.i no need to oddcode in this method.i need to read the value from the excelsheet, and send to this method as string
0

this input value should be in string,from the excel sheet im getting the integer value, in this need to change the inputvalue into string.if i change inputvalue as integer in this method, sendkeys(inbuild java method)doesnt accept the integer inputvalue.i no need to oddcode in this method.i need to read the value from the excelsheet, and send to this method.

public static void inttypeIn(String objLocator, String inputValue){

      try
      {
          findWebElement(objLocator);

      webElement.sendKeys(inputValue);
      webElement.sendKeys(Keys.TAB);

        APP_LOGS.debug("Typing '" + inputValue + "' in : " + locatorDescription);
      }
      catch (Exception e)
      {
            APP_LOGS.debug("FAIL : The locator "+objLocator+" of description '"+locatorDescription+"': does not exists in webpage:");
            Reporting.fail("FAIL : The locator '"+objLocator+"' of description '"+locatorDescription+"': does not exists in webpage:");
      }
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.