java.lang.NullPointerException

Code:

package HSBC;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;

public class test {
public WebDriver driver;
public String baseUrl;
@SuppressWarnings(“unused”)
private boolean acceptNextAlert = true;
@SuppressWarnings(“unused”)
private StringBuffer verificationErrors = new StringBuffer();
public String st1,st2;
public int xRows, xCols;
//public String xData[][][][];
public String xData[][]; // creates an empty 2-d array named xData
public String xPath, xPath_res;

@BeforeMethod
public void setUp() throws Exception
{

xPath = “D:\\Lifespeed\\src\\testData\\State_Data_new.xlsx”;

xPath_res = “D:\\Lifespeed\\src\\testData\\State_Data_result.xlsx”;

//xPath = “D:\\Webdriver\\Lifespeed\\src\\testData\\State_Data_new.xlsx”;

//xPath_res = “D:\\Webdriver\\Lifespeed\\src\\testData\\State_Data_result.xlsx”;

xlRead(xPath);

Thread.sleep(1000);

driver=new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

driver.get(“https://abc”);

//LOGIN

driver.findElement(By.id(“txtPartnerCode”)).clear();
driver.findElement(By.id(“txtPartnerCode”)).sendKeys(“abc”);
driver.findElement(By.id(“txtuserid”)).clear();
driver.findElement(By.id(“txtuserid”)).sendKeys(“abc”);
driver.findElement(By.id(“txtpassword”)).clear();
driver.findElement(By.id(“txtpassword”)).sendKeys(“abc”);
driver.findElement(By.id(“btnTemplateLogin”)).click();
Thread.sleep(2000);
}

@Test
public void testUntitled() throws Exception {

String States,OwnerValue,Owner,vExecute;
int i;

for (i=1; i<xRows; i=i+1)

{
System.out.println(“Row # ” + i + ” is executing”);

States = xData[i][0];
//vPassword = xData[i][1];

OwnerValue = xData[i][1];
System.out.println(“Owner selected in Excel Sheet is :” + OwnerValue);

Owner = xData[i][2];
System.out.println(“Owner selected in Excel Sheet is :” + Owner);

vExecute = xData[i][3];

System.out.println(“State selected in Excel Sheet is :” + States);

if (vExecute.equals(“Y”))

{

//PRODUCT SELECTION

driver.findElement(By.linkText(“New Application”)).click();
new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlDistributor”))).selectByVisibleText(“HSBC Distributor”);

new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlSolicitationState”))).selectByVisibleText(States);

String st = new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlSolicitationState”))).getFirstSelectedOption().getText();
System.out.println(“Selected State in Wizard is :”+st);

new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlProductType”))).selectByVisibleText(“Whole Life”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlInsuranceCarrier”))).selectByVisibleText(“Liberty”);
driver.findElement(By.id(“ctl00_cplWizard_txtFirstName_0”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_txtFirstName_0”)).sendKeys(“Aish”);
driver.findElement(By.id(“ctl00_cplWizard_txtLastName_0”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_txtLastName_0”)).sendKeys(“Vikki”);
driver.findElement(By.id(“ctl00_cplWizard_txtAgentcode_0”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_txtAgentcode_0”)).sendKeys(“65”);
driver.findElement(By.id(“ctl00_cplWizard_txtSSN_0”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_txtSSN_0”)).sendKeys(“521452147”);
driver.findElement(By.id(“ctl00_ibtnNext”)).click();

// Policy Configuration
new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlPurposeOfPolicy”))).selectByVisibleText(“Business (Buy / Sell)”);
driver.findElement(By.id(“ctl00_cplWizard_txtCoverageAmount”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_txtCoverageAmount”)).sendKeys(“100000”);

if (OwnerValue.equals(“1.0”))
{
driver.findElement(By.id(“ctl00_cplWizard_radBannerIsOwnerSame_0”)).click();

new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlPayorSameAs”))).selectByVisibleText(“Owner”);

driver.findElement(By.id(“ctl00_cplWizard_rdlExchange_0”)).click();
driver.findElement(By.id(“ctl00_ibtnNext”)).click();
}
else

{
driver.findElement(By.id(“ctl00_cplWizard_radBannerIsOwnerSame_1”)).click();

//boolean ctl00_cplWizard_radBannerIsOwnerSame_1 = driver.findElement(By.id(“ctl00_cplWizard_radBannerIsOwnerSame_1”)).isSelected();
// if(ctl00_cplWizard_radBannerIsOwnerSame_1==true){

//Select owner type person
//Select person=new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlOwnerEntityType”)));
// person.selectByVisibleText(“Person”);
//Thread.sleep(2000);
// String Owner_Type=person.getFirstSelectedOption().getText();
// System.out.println(“Selected owner type is :”+Owner_Type);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlOwnerEntityType”))).selectByVisibleText(Owner);

st1 = new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlOwnerEntityType”))).getFirstSelectedOption().getText();
System.out.println(“Selected State in Wizard is :”+st1);

new Select(driver.findElement(By.id(“ctl00_cplWizard_ddlPayorSameAs”))).selectByVisibleText(“Owner”);

driver.findElement(By.id(“ctl00_cplWizard_rdlExchange_0”)).click();
driver.findElement(By.id(“ctl00_ibtnNext”)).click();

//Insured

driver.findElement(By.id(“ctl00_ibtnNext”)).click();

//Owner
if(st1.equals(“Person”))

{

new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ddlPrefix”))).selectByVisibleText(“Mr.”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtFirstName”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtFirstName”)).sendKeys(“mark”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtLastName”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtLastName”)).sendKeys(“Jhonson”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_TaxIDControl1_rdbTaxNumber_0”)).click();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_TaxIDControl1_txtTaxNumber”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_TaxIDControl1_txtTaxNumber”)).sendKeys(“123312321”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_radioGender_1”)).click();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtDOB”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtDOB”)).sendKeys(“11/11/1985”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ddlCitizenship”))).selectByVisibleText(“United States”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_txtAddress1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_txtAddress1”)).sendKeys(“Test”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_txtCity”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_txtCity”)).sendKeys(“Atlanta”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_ddlState”))).selectByVisibleText(“Virginia”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_ucPostalCodeControl1_txtZipCode”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_PhysicalAddress_ucPostalCodeControl1_txtZipCode”)).sendKeys(“20110”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtBPhone”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtBPhone”)).sendKeys(“2342342342”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtPhone”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtPhone”)).sendKeys(“2342342342”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtOccupation”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtOccupation”)).sendKeys(“Software”);
driver.findElement(By.id(“ctl00_ibtnNext”)).click();
}

else if(st1.equals(“Corporation”))

{

driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtEntityName”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtEntityName”)).sendKeys(“Software”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_TaxIDControl1_txtTaxNumber”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_TaxIDControl1_txtTaxNumber”)).sendKeys(“324234232”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtLineOfBusiness”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtLineOfBusiness”)).sendKeys(“Key”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ddlEntityType”))).selectByVisibleText(“Unincorporated Association”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtEstablishmentDate”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtEstablishmentDate”)).sendKeys(“11/11/1980”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_txtAddress1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_txtAddress1”)).sendKeys(“Test”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_txtCity”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_txtCity”)).sendKeys(“Test”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_ddlState”))).selectByVisibleText(“Virginia”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_ucPostalCodeControl1_txtZipCode”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_EntityPhysicalAddress_0_ucPostalCodeControl1_txtZipCode”)).sendKeys(“22222”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtEntityPhone_0”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtEntityPhone_0”)).sendKeys(“3534535345”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_ddlEntityPrefix_1”))).selectByVisibleText(“Mr.”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityFirstName_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityFirstName_1”)).sendKeys(“Aishwarya”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityLastName_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityLastName_1”)).sendKeys(“Vikki”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_TaxIDControl_1_txtTaxNumber”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_TaxIDControl_1_txtTaxNumber”)).sendKeys(“11/11/198”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_TaxIDControl_1_txtTaxNumber”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_TaxIDControl_1_txtTaxNumber”)).sendKeys(“234234234”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtDateOfBirth_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtDateOfBirth_1”)).sendKeys(“11/11/1980”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtTitlePoistion_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtTitlePoistion_1”)).sendKeys(“23423423423423”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtYearsWithEmployer_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtYearsWithEmployer_1”)).sendKeys(“198”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtYearsWithEmployer_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtYearsWithEmployer_1”)).sendKeys(“32”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtPerOwnership_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtPerOwnership_1”)).sendKeys(“100”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtAddress1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtAddress1”)).sendKeys(“hj”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtCity”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtCity”)).sendKeys(“df”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ddlState”))).selectByVisibleText(“Virginia”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ucPostalCodeControl1_txtZipCode”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ucPostalCodeControl1_txtZipCode”)).sendKeys(“22222”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityPhone_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityPhone_1”)).sendKeys(“3563453453”);
driver.findElement(By.id(“ctl00_ibtnNext”)).click();
}

else if (st1.equals(“Trust”))

{

driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtTrustName”)).sendKeys(“JCB”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtTaxNumber”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtTaxNumber”)).sendKeys(“123131312”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtAmendmentdate”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtAmendmentdate”)).sendKeys(“11/11/1980”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ddlState”))).selectByVisibleText(“Alaska”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtNameOfTGS”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtNameOfTGS”)).sendKeys(“vIKKI”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtNameOfTGS”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtNameOfTGS”)).sendKeys(“jack”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_rblTrustirrevocable_0”)).click();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_txtAddress1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_txtAddress1”)).sendKeys(“ds”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_txtCity”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_txtCity”)).sendKeys(“sd”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_ddlState”)).click();
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_ddlState”))).selectByVisibleText(“Virginia”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_ucPostalCodeControl1_txtZipCode”)).click();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_ucPostalCodeControl1_txtZipCode”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ucPhysicalStreetAdd_ucPostalCodeControl1_txtZipCode”)).sendKeys(“22222”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtTrustPhone”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtTrustPhone”)).sendKeys(“2342423423”);
driver.findElement(By.id(“tdtxtBusinessPhone”)).click();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtBPhone”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtBPhone”)).sendKeys(“234234234”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtBPhone”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_txtBPhone”)).sendKeys(“2342342342”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_ddlEntityPrefix_1”))).selectByVisibleText(“Mr.”);
driver.findElement(By.cssSelector(“#ctl00_cplWizard_ctl00_ctlEntityDetail_ddlEntityPrefix_1 > option[value=\”1\”]”)).click();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityFirstName_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityFirstName_1”)).sendKeys(“amark”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityLastName_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityLastName_1”)).sendKeys(“test”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_TaxIDControl_1_txtTaxNumber”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_TaxIDControl_1_txtTaxNumber”)).sendKeys(“231312312”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtDateOfBirth_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtDateOfBirth_1”)).sendKeys(“11/11/1980”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtTitlePoistion_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtTitlePoistion_1”)).sendKeys(“QA”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtYearsWithEmployer_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtYearsWithEmployer_1”)).sendKeys(“22”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtPerOwnership_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtPerOwnership_1”)).sendKeys(“100”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtAddress1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtAddress1”)).sendKeys(“234”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtCity”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_txtCity”)).sendKeys(“SDF”);
new Select(driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ddlState”))).selectByVisibleText(“Virginia”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ucPostalCodeControl1_txtZipCode”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ucPostalCodeControl1_txtZipCode”)).sendKeys(“23234”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ucPostalCodeControl1_txtPostalCode”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_EntityAddress_1_ucPostalCodeControl1_txtPostalCode”)).sendKeys(“2342”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityPhone_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityPhone_1”)).sendKeys(“23423424”);
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityPhone_1”)).clear();
driver.findElement(By.id(“ctl00_cplWizard_ctl00_ctlEntityDetail_txtEntityPhone_1”)).sendKeys(“2342342434”);
driver.findElement(By.id(“ctl00_ibtnNextFooter”)).click();
}}
//Financial Detail

driver.findElement(By.id(“ctl00_ibtnNext”)).click();

// Payment

driver.findElement(By.id(“ctl00_ibtnNext”)).click();

//PVC and Owner Experience

driver.findElement(By.id(“ctl00_ibtnNext”)).click();
//Life Insurance

driver.findElement(By.id(“ctl00_ibtnNext”)).click();

//Agent Report

driver.findElement(By.id(“ctl00_ibtnNext”)).click();

//liberty Additional

driver.findElement(By.id(“ctl00_ibtnNext”)).click();

Thread.sleep(2000);
}

else {
System.out.println(“Data in row ” + i + ” not executed.”);
}

Thread.sleep(2000);
}

}

@AfterMethod
public void tearDown() throws Exception {

//xlwrite(xPath_res, xData); // write the data from the java code back into excel application
driver.quit();
}

public void xlRead(String xPath) throws Exception{
File myxl = new File(xPath);
FileInputStream myStream = new FileInputStream(myxl);

XSSFWorkbook myWB = new XSSFWorkbook(myStream);

XSSFSheet mySheet = myWB.getSheetAt(0);
xRows = mySheet.getLastRowNum()+1;
xCols = mySheet.getRow(0).getLastCellNum();

System.out.println(“Rows are ” + xRows);
System.out.println(“Cols are ” + xCols);
//String[][] xData = new String[xRows][xCols];
xData = new String[xRows][xCols];
for (int i = 0; i < xRows; i++) {
XSSFRow row = mySheet.getRow(i);
for (int j = 0; j < xCols; j++)
{

XSSFCell cell = row.getCell(j); // To read value from each col in each row
String value = cellToString(cell);
xData[i][j] = value;
System.out.print(value);
System.out.print(“@@”);
}
//System.out.println(“”);

}

}

public static String cellToString(XSSFCell cell) {
// This function will convert an object of type excel cell to a string value
int type = cell.getCellType();
Object result;
switch (type) {
case XSSFCell.CELL_TYPE_NUMERIC: //0
result = cell.getNumericCellValue();
break;
case XSSFCell.CELL_TYPE_STRING: //1
result = cell.getStringCellValue();
break;
case XSSFCell.CELL_TYPE_FORMULA: //2
throw new RuntimeException(“We can’t evaluate formulas in Java”);
case XSSFCell.CELL_TYPE_BLANK: //3
result = “-“;
break;
case XSSFCell.CELL_TYPE_BOOLEAN: //4
result = cell.getBooleanCellValue();
break;
case XSSFCell.CELL_TYPE_ERROR: //5
throw new RuntimeException (“This cell has an error”);
default:
throw new RuntimeException(“We don’t support this cell type: ” + type);
}
return result.toString();
}
public void xlwrite(String xlPath, String[][] xldata) throws Exception {
System.out.println(“Inside XL Write”);
File outFile = new File(xlPath);
XSSFWorkbook wb = new XSSFWorkbook();
// Make a worksheet in the XL document created
/*XSSFSheet osheet = wb.setSheetName(1,”TEST”);*/
XSSFSheet osheet = wb.createSheet(“TESTRESULTS”);
// Create row at index zero ( Top Row)
for (int myrow = 0; myrow < xRows; myrow++) {
//System.out.println(“Inside XL Write”);
XSSFRow row = osheet.createRow(myrow);
// Create a cell at index zero ( Top Left)
for (int mycol = 0; mycol < xCols; mycol++) {
XSSFCell cell = row.createCell(mycol);
// Lets make the cell a string type
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
// Type some content
cell.setCellValue(xldata[myrow][mycol]);
//System.out.print(“…” + xldata[myrow][mycol]);
}
//System.out.println(“………………”);
// The Output file is where the xls will be created
FileOutputStream fOut = new FileOutputStream(outFile);
// Write the XL sheet
wb.write(fOut);
fOut.flush();
// // Done Deal..
fOut.close();
}
}
}

Error LOG

[TestNG] Running:
C:\Users\paramesh.u\AppData\Local\Temp\testng-eclipse–71720663\testng-customsuite.xml

Rows are 24
Cols are 4
State@@OwnerValue@@Owner@@Execute@@California@@0.0@@Null@@Y@@California@@1.0@@Corporation@@Y@@Delaware@@1.0@@Trust@@Y@@District of Columbia@@1.0@@Person@@Y@@FAILED CONFIGURATION: @BeforeMethod setUp
java.lang.NullPointerException
at HSBC.test.xlRead(test.java:427)
at HSBC.test.setUp(test.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: testUntitled

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.jq.Main@402e11: 72 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 17 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@66eb46: 12 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1e7ce87: 97 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@f38f09: 10 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@39b27b: 12 ms

Default Asked on August 21, 2014 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Hi,

    Its a null pointer and it seems that the excel files are either not present or the sheet that you are trying to access is not present in the excel.

    Also while asking these types of questions just paste the relevant part of the code. Also, I would request you to do a preliminary level of debugging yourself before asking the question, so that you are able to explain your problem better. This will enable the community members to give you detailed answers.

    Thanks
    Virender

    Professor Answered on August 21, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.