如何使用硒webdriver将数字转换为Excel表格中的字符串 将Excel中的值作为10传递给Excel表格,但在Web应用程序中将其作为10.0输入。 由于事先如何使用硒webdriver将excel表格中的数字转换为字符串
回答
解决方案1
我希望你使用的是Apache POI从Excel中读取。 在这种情况下,这个样本可以帮助你
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());
}
对于价值1234在Excel中cell.getNumericCellValue()将返回1234.0和cell.getRawValue()将返回1234
解决方案2
如果您不能在读取Excel的地方修改任何内容,请在输入数值前使用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");
}
}
感谢共享..我无法奇怪的输入value.soo CodeGo.net,只要我需要改变的值应改变只在Excel表中不是在程序中。 – Vids 2014-10-30 04:26:37
请参阅下面的程序@sachin – Vids 2014-10-30 05:26:15
public static void inttypeIn(String objLocator,String inputValue){ try {findWebElement(objLocator); webElement.sendKeys(inputValue); webElement.sendKeys(Keys.TAB); APP_LOGS.debug( “打字 '” + + inputValue的 “' 中:locatorDescription); } 赶上(例外五) { APP_LOGS.debug(” FAIL: “+ objLocator +” 的描述“定位器 ”+ locatorDescription +“ ':不存在于网页中:“); – Vids 2014-10-30 08:53:42
这个输入值应该是字符串,从excel表格中获取整数值,在这个需要将inputvalue改成string.if我改变inputvalue为整数,在这个方法中,sendkeys(inbuild java方法)不接受整数输入值.i在这个方法中不需要奇怪的代码。我需要从excelsheet中读取值并发送给这个方法。
公共静态无效inttypeIn(字符串objLocator,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:");
}
}
- 1. 将sci格式的数字转换为excel中的字符串
- 2. 如何将.NET标准格式字符串转换为Excel格式字符串
- 3. 如何在Excel的PowerQuery中将整数转换为字符串
- 4. 如何使用硒webdriver从下拉列表中选定的选项将文本转换为字符串变量?
- 5. 如何将数字转换为带格式的字符串?
- 6. 如何使用C#将字符串转换为PascalCase字符串?
- 7. 将字符串数组转换为JSON格式的字符串
- 8. 如何在Excel VBA中将整数转换为字符串?
- 9. 将excel中的数字转换为字符串?
- 10. 如何使用openpyxl将格式化为字符串的日期转换为Excel中的数字
- 11. 如何使用json.net将数据表转换为json字符串?
- 12. 将字符串或字符串[]转换为使用Groovy列表
- 13. 如何将时间格式从数字转换为字符串?
- 14. 如何将字符串的字符串转换为字符?
- 15. 如何将字符串中的字母转换为数字 - C++
- 16. 如何将字符串列表转换为数字numpy数组?
- 17. 如何使用freemarker将字符串转换为数字?
- 18. 如何使用jq将数字转换为字符串?
- 19. 如何将字符串列表转换为查询字符串?
- 20. 将“字符串”和“数字串”的列表转换为“数字串”被转换为数字的列表
- 21. 在watir-webdriver中将select_list选项转换为字符串数组?
- 22. 如何将字符串转换为Perl中的unicode字符串
- 23. 将数字转换为excel的base26列字符串。郎perl的
- 24. 如何将字符串转换为Excel中的日期?
- 25. 如何将字符串转换为Excel中的日期/时间?
- 26. 将字符串转换为字列表?
- 27. 将字符串转换为格式为
- 28. 如何将字符串数组转换为字符串?
- 29. 如何将数据框转换为RDD [字符串,字符串]?
- 30. 如何将字符串转换为字符串数组String()?
你读入一个字符串从Excel价值? – 2014-10-29 12:19:09
这听起来像通过。您使用什么方法来设置单元格中的值?一些示例代码在这里非常有帮助 – bcar 2014-10-29 12:35:23
im从excel sheet中读取文本值10,但是当它进入webelement时,它将值输入为10.0。我也改变了类别在Excel中的文本。 – Vids 2014-10-29 12:45:45