Issue while sending integers through sendkeys of selenium

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue while sending integers through sendkeys of selenium

stanley jones
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;

}
}







--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/8fb166ab-3e0c-4f81-af50-b76f5cc8cb7b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Issue while sending integers through sendkeys of selenium

Krishna Kumar
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



On Thursday, 22 August 2013 04:20:09 UTC+5:30, stanley jones wrote:
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;

}
}







--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a79e2ffd-bc74-4ea7-9777-cb3a97982d77%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Issue while sending integers through sendkeys of selenium

Neftali G Reyes
That doesn't work in c#.

On Friday, August 23, 2013 at 2:36:56 AM UTC-5, Krishna Kumar wrote:
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



On Thursday, 22 August 2013 04:20:09 UTC+5:30, stanley jones wrote:
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("<a href="http://www.google.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com&#39;;return true;" onclick="this.href=&#39;http://www.google.com&#39;;return true;">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;

}
}







--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ab24f489-c104-46f0-802d-3cfaa7cff815%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Issue while sending integers through sendkeys of selenium

shraddha gupta
In reply to this post by Krishna Kumar
Thanks for this options, it worked fine.

Regards,
Shraddha

On Friday, August 23, 2013 at 1:06:56 PM UTC+5:30, Krishna Kumar wrote:
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



On Thursday, 22 August 2013 04:20:09 UTC+5:30, stanley jones wrote:
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("<a href="http://www.google.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com&#39;;return true;" onclick="this.href=&#39;http://www.google.com&#39;;return true;">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;

}
}







--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ffd4a276-2769-49b8-b474-6d04e978fc47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.