简体   繁体   中英

Using Java variables with Sikuli in Selenium-Webdriver

The code below is a Java code in Selenium Webdriver. The code reads a long list from an excel sheet. It stores the values in each excel cell in variables, LastName and FirstName . I need to use the variables in a query, after navigating to SQL Server management studio database. This is where am having issues. when I use the command 'screen.type(LastName);', the variable LastName throws "cannot be resolved to a variable" error.

How do I use the variables LastName and FirstName defined in Java in Sikuli.

File src = new File ("C:\\EmployeeList.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(0);
int rowcount=sheet1.getLastRowNum();
System.out.println("Total Row is :" + rowcount);

for (int i=0; i<rowcount;i++) {
    String LastName=sheet1.getRow(i).getCell(0).getStringCellValue();   
    String FirstName=sheet1.getRow(i).getCell(1).getStringCellValue();  
    System.out.println("Data Employee List is " +i+ " "+"is "+ LastName+ ", "+FirstName+");
}

wb.close();

//Navigated into SQL Server management studio database
  screen.type(LastName);

LastName is declared in the for loop local scope, so it doesn't exist outside the for . You need to declare it outside

String lastName, firstName;
for (int i = 0 ; i < rowcount ; i++) {
    lastName = sheet1.getRow(i).getCell(0).getStringCellValue();   
    firstName = sheet1.getRow(i).getCell(1).getStringCellValue();  
    System.out.println("Data Employee List is " + i + " " + "is " + lastName + ", " + firstName);
}

screen.type(lastName);

I'm not sure if this on purpose, but screen.type(lastName); will use only the last value of lastName . If you want to use all of them insert it into the loop. In that case you can leave the lastName declaration inside the for

for (int i = 0 ; i < rowcount ; i++) {
    String lastName = sheet1.getRow(i).getCell(0).getStringCellValue();   
    String firstName = sheet1.getRow(i).getCell(1).getStringCellValue();
    System.out.println("Data Employee List is " + i + " " + "is " + lastName + ", " + firstName);
    screen.type(lastName);
}

By the way, variables in Java should start with lower case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM