问题
Can anyone please suggest me how can I read an excel-sheet in my local-drive say"C:\company_names.xls" and populate into the text boxes present in a webpage.
I will explain the test case scenario as below:
1)The webpage should first open in a Firefox. 2)The left navigation should be clicked "companylist" 3)Then a drop-down value name company list(by default) should be selected. 4)Then create button should be click which takes the page to another page which has two text boxes with names say "Company names" and company products" 5)The excelsheet with entries for these two textboxes is in the local drive "C:\text.xls". This excel sheet has total number of 100 records. 6)Each of the two entries companynames and company products should be fetched from excel sheet and populated in the textboxes in the webpage and then a submit button should be clicked. 7)Then another submit button.
I am able to create the automation by hard-coding two sample values for the first entry.Can anyone help me out how to read the value from excelsheet and populate in the text boxes of the webpage?
I have pasted below the hardcoded example that i have done so far, please help me out in how to approach with the excelsheet reading and populating of the data into webpage.
public void submit()throws Exception
{
selenium.start();
selenium.setSpeed("1000");
selenium.open("URL");
selenium.windowFocus();
selenium.windowMaximize();
selenium.click("link=companylist");
selenium.waitForPageToLoad("30000");
selenium.select("//select[@name='comp_id']","label=company");
selenium.waitForPageToLoad("30000");
selenium.click("name=open");
selenium.waitForPageToLoad("30000");
selenium.type("id=company_names", "test5");
selenium.type("id=company_products", "test6");
selenium.click("css=input.button");
selenium.waitForPageToLoad("30000");
selenium.click("name=action");
selenium.waitForPageToLoad("30000");
selenium.click("name=action");
selenium.waitForPageToLoad("30000");
}
public void tearDown() throws Exception
{
selenium.close();
selenium.stop();
selenium.refresh();
}
回答1:
public static String[][] readData(String readfileName, String readsheetName) throws IOException, BiffException
{
File infoFile = new File(readfileName);
Workbook infoWorkBook = Workbook.getWorkbook(infoFile);
Sheet infoSheet = infoWorkBook.getSheet(readsheetName);
int infoRows = infoSheet.getRows();
int infoColumns = infoSheet.getColumns();
String[][] column = new String[infoColumns][infoRows];
for(int i=1; i< infoRows; i++)
{
for(int j1=0; j1<infoColumns; j1++)
{
column[j1][i] = infoSheet.getCell(j1, i).getContents();
// System.out.println(column[j1][i]);
}
}
return column;
}
回答2:
I would use the Apache POI libraries for this. Check out POI-HSSF and POI-XSSF for the Excel libraries.
回答3:
Not sure what you have tried but there is Excel JDBC Driver. Might be helpful to read data from Excel. Visit: http://sourceforge.net/projects/xlsql/
来源:https://stackoverflow.com/questions/15719944/read-the-rows-in-excelsheet-and-populate-in-webpage-text-box