我正在使用Java程序读取和写入现有的.xlsx文件(相同的文件),但文件已损坏,文件大小变为零字节,导致"org.apache.poi.EmptyFileException:提供的文件为空(零字节长)".
还有一件事 - 这种情况不会持续发生.该程序在大多数情况下正在读取和写入文件,但在10-15次运行中发生一次.如果有人有解决方案,那将会很有帮助.顺便说一句,我正在使用Apache POI 3.13.
阅读文件程序:
public String getExcelData(String sheetName, int rowNum, int colNum){
String retVal = null;
try {
FileInputStream fis = new FileInputStream("/Absolute/File/Path/Test-File.xlsx");
Workbook wb = WorkbookFactory.create(fis);
Sheet s = wb.getSheet(sheetName);
Row r = s.getRow(rowNum);
Cell c = r.getCell(colNum);
retVal=(c.getStringCellValue());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return …Run Code Online (Sandbox Code Playgroud) 我想选择一个位于弹出窗口中的iframe元素.我可以进入弹出窗口,但无法找到iframe.下面是弹出窗口的html代码.
<html>
<head></head>
<body>
<iframe width="100%" height="100%" border="0" src="/some/url.do?parameter=getData">
<html>
.
.
<table id="ec_table" class="tableRegion" width="20%" cellspacing="1" cellpadding="2"
border="0">
<tr class="even">
<td>
<input type="radio" value="173" name="hier_data_id">
</td>
</tr>
.
.
</html>
</iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在这里,我想点击位于iframe内的单选按钮.我使用下面的代码在iframe中切换,但它没有切换到iframe.
driver.switchTo().frame(myD.findElement(By.tag("iframe")));
Run Code Online (Sandbox Code Playgroud)
由于iframe没有id,我发现难以在iframe中找到元素.
有谁知道我怎么做...?
提前致谢.