【问题标题】:Using Java variables with Sikuli in Selenium-Webdriver在 Selenium-Webdriver 中使用带有 Sikuli 的 Java 变量
【发布时间】:2016-03-27 21:08:29
【问题描述】:

下面的代码是 Selenium Webdriver 中的 Java 代码。该代码从 Excel 工作表中读取一个长列表。它将每个 Excel 单元格中的值存储在变量 LastNameFirstName 中。导航到 SQL Server 管理工作室数据库后,我需要在查询中使用变量。这是我遇到问题的地方。当我使用命令 'screen.type(LastName);' 时,变量 LastName 会抛出“无法解析为变量”错误。

如何在Sikuli 中使用Java 中定义的变量LastNameFirstName

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);

【问题讨论】:

    标签: java selenium-webdriver sikuli


    【解决方案1】:

    LastNamefor 循环本地范围内声明,因此它不存在于for 之外。你需要在外面声明它

    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);
    

    我不确定这是否是故意的,但screen.type(lastName); 将仅使用lastNamelast 值。如果您想使用所有这些,请将其插入循环中。在这种情况下,您可以将lastName 声明留在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);
    }
    

    顺便说一句,Java中的变量应该以小写开头。

    【讨论】:

    • 谢谢!感谢帮助。目的是从 excel 表中一行的每个单元格中获取值。使用 SQL 查询中的值,然后返回到 Excel 工作表中的下一行。
    猜你喜欢
    • 1970-01-01
    • 2015-09-12
    • 2013-10-10
    • 1970-01-01
    • 2018-10-03
    • 2012-08-19
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多