我需要使用 Jxl 参数化来参数化 5 个文本字段和一个按钮。我只做了两个文本框,我不知道如何同时参数化这 5 个文本框。
public class test {
public static void main(String[] args) throws InterruptedException, BiffException, IOException {
// TODO Auto-generated method stub
String FilePath = "F:/ISTP Testing/Module 2/Seleniume/project/Spaco_DataEntryTest_ContactPage.xls";
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);
// TO get the access to the sheet
Sheet sh = wb.getSheet("Sheet1");
String BaseURL="http://istp.in/changathionlinebeta/contact_us.php";
WebDriver wd=new FirefoxDriver();
wd.get(BaseURL);
// To get the number of rows present in sheet
int totalNoOfRows = sh.getRows();
// To get the number of columns present in sheet
int totalNoOfCols = sh.getColumns();
for (int row = 1; row < totalNoOfRows; row++) {
for (int col = 0; col < totalNoOfCols; col++) {
System.out.print(sh.getCell(col, row).getContents() + "\t");
Thread.sleep(3000);
if(col%2==0)
{
wd.findElement(By.id("name")).sendKeys(sh.getCell(col, row).getContents());
}else{
wd.findElement(By.id("email")).sendKeys(sh.getCell(col, row).getContents());
}
}
System.out.println();
}
wd.close();
System.exit(0);
}
}
最佳答案
Rudziankoŭ 是的,但是。
1 > 创建 class SubmitPageObject
包含所有属性(姓名、电子邮件、地址...)
2 > 在您的程序中创建从工作簿获取信息并将其分配给 List<SubmitPageObject> spo = new List<SubmitPageObject>();
的方法
..
spo.Add(new SubmitPageObject(name,email,...))
3 > 最后一步是循环列表:
wd.findElement(By.id("name")).sendKeys(spo[i].name);
wd.findElement(By.id("email")).sendKeys(spo[i].email);
wd.findElement(By.id("phone")).sendKeys(spo[i].phone);
...
关于java - 如何参数化两个以上的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37940233/