I wrote a selenium code to read values from an excel sheet which contains 2 columns.I need to input these to 2 text boxes in a webpage .I do not want to use TestNG at this point .My issue is every time the browser opens with the webpage for each entry ie each row . Say I have 10 rows in the excel sheet 10 web pages are opened and each would input to the text boxes .How can I rewrite my code to open a single browser and input values one by one .
public class Insert {
public static void main(String[] args)
{
try {
FileInputStream fis = new FileInputStream("F:\\Book4.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet = wb.getSheet("testdata");
for(int count = 1;count<=sheet.getLastRowNum();count++)
{
XSSFRow row = sheet.getRow(count);
System.out.println("Running test case " + row.getCell(0).toString());
runTest(row.getCell(1).toString(),row.getCell(2).toString());
}
fis.close();
} catch (IOException e) {
System.out.println("Test data file not found");
}
}
public static void runTest(String name,String mailid)
{
WebDriver driver=new FirefoxDriver();
driver.get("http://www.deal4loans.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("html/body/div[4]/div/div/div[1]/a[1]")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input")).sendKeys(name);
driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[2]/td[2]/input")).sendKeys(mailid);
}
}