Issue while sending integers through sendkeys of selenium

2,125 views
Skip to first unread message

stanley jones

unread,
Aug 21, 2013, 6:50:09 PM8/21/13
to seleniu...@googlegroups.com
Hello all i am having trouble in figuring out how to resolve the below issues.
1. In the below code if i don't convert the integers to string that read from excel the sendkeys is not allowing me to send the input.
 2.After converting the integers to strings, the code is showing an error to initialize the variables vURL,vEmail,vPswd,vCnfmPswd,vCustAccNum,vZipCode.
 3. If i initialize the above variables and run the code, i am getting null point exception.Could you please look into the below code and help me in resolving these issues.

I have created the below class to read the data model
public class CustomerData {
private String vURL;
private String vEmail;
private String vPswd;
private String vCnfmPswd;
private int vCustAccNum;
private int vZipCode;
public String getvURL() {
return vURL;
}
public void setvURL(String vURL) {
this.vURL = vURL;
}
public String getvEmail() {
return vEmail;
}
public void setvEmail(String vEmail) {
this.vEmail = vEmail;
}
public String getvPswd() {
return vPswd;
}
public void setvPswd(String vPswd) {
this.vPswd = vPswd;
}
public String getvCnfmPswd() {
return vCnfmPswd;
}
public void setvCnfmPswd(String vCnfmPswd) {
this.vCnfmPswd = vCnfmPswd;
}
public int getvCustAccNum() {
return vCustAccNum;
}
public void setvCustAccNum(int vCustAccNum) {
this.vCustAccNum = vCustAccNum;
}
public double getvZipCode() {
return vZipCode;
}
public void setvZipCode(int vZipCode) {
this.vZipCode = vZipCode;
}
}


MyActualSeleniumCode:
 

public class Sample {
private WebDriver driver;
int xRows, xCols;

@Before
public void setUp() throws Exception {

}

@Test
public void CustInfo() throws Exception {
// String vURL,vEmail,vPswd,vCnfmPswd;
// int vCustAccNum;
// int vZipCode; 
long iWait;
int Size;
// Read Test Data from Excel

String xlPath = "C:\\SCE docs\\Automation\\InputData_Registration.xls";
CustomerData[] customerData = getExcelData(xlPath,"AccountHolderRegistration");
System.setProperty("webdriver.chrome.driver", "c:\\chromedriver.exe");
     driver = new ChromeDriver();
 //    driver = new FirefoxDriver();
  //  driver.get("http://www.google.com");
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
     iWait=3000;
 
for (int k=1; k<xRows; k++) 
     { 
    
               driver.navigate().to(vURL);
               driver.findElement(By.linkText("Register")).click(); 
               driver.findElement(By.id("emailInputBox_input")).clear(); 
               driver.findElement(By.id("emailInputBox_input")).sendKeys(customerData.getvEmail()); 
               driver.findElement(By.id("pwdInputBox_input")).clear(); 
               driver.findElement(By.id("pwdInputBox_input")).sendKeys(vPswd); 
               driver.findElement(By.id("confirmpwd_input")).clear(); 
               driver.findElement(By.id("confirmpwd_input")).sendKeys(vCnfmPswd); 
               driver.findElement(By.id("radio1")).click();
               driver.findElement(By.id("accountInputBox_input")).sendKeys(Integer.toString(vCustAccNum));
               driver.findElement(By.id("accountInputBox_input")).clear(); 
               driver.findElement(By.id("zipcodeBox_input")).sendKeys(Integer.toString(vZipCode));
               driver.findElement(By.id("zipcodeBox_input")).clear(); 
               driver.findElement(By.id("terms3")).click(); 
                    
    
     }
    }
public CustomerData[] getExcelData(String Path, String shtName)
throws Exception {
File myxl = new File(Path);
FileInputStream fi = new FileInputStream(myxl);
HSSFWorkbook myWB = new HSSFWorkbook(fi);
HSSFSheet mySheet = myWB.getSheet(shtName);

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

CustomerData[] customerDataList = new CustomerData[xRows];
for (int i = 1; i < xRows; i++) {
HSSFRow row = mySheet.getRow(i);

CustomerData customerDetails = new CustomerData();
customerDetails.setvURL(row.getCell(1).getStringCellValue());
customerDetails.setvEmail(row.getCell(2).getStringCellValue());
customerDetails.setvPswd(row.getCell(3).getStringCellValue());
customerDetails.setvCnfmPswd(row.getCell(4).getStringCellValue());
// System.out.println("value "+row.getCell(0));
customerDetails.setvCustAccNum((int) row.getCell(5).getNumericCellValue());
customerDetails.setvZipCode((int) row.getCell(6).getNumericCellValue());
customerDataList[i] = customerDetails; 
System.out.println("row 2: "+(row.getCell(5)));
}
//System.out.println (" After the loop the Excel data" + customerDataList);
return customerDataList;

}
}







Krishna Kumar

unread,
Aug 23, 2013, 3:36:56 AM8/23/13
to seleniu...@googlegroups.com
Hi,

While you entering the data into Excel sheet for Integers use the format like below:

Instead of enter 123 directly; enter '123. Then it will take the data properly.

I hope it works for you.


Thanks,
Krishna
Message has been deleted

shraddha gupta

unread,
May 24, 2018, 5:42:23 AM5/24/18
to Selenium Users
Thanks for this options, it worked fine.

Regards,
Shraddha
Reply all
Reply to author
Forward
0 new messages