-2

如何为多个客户在 excel 中给出的输入编写 for-loop 以登录到 yahoo。我想要硒数据驱动的测试。

在这里,我需要 B 列而不是 A 列的值,并且我的行需要增加。

那么如何编写for循环

column A   ..        column B
=====================================
username              >>> waxy@yahoo.com

password              >>>>123456

username              >>>>ABC@yahoo.com

password              >>>>123456

我试过下面的代码,

public class yahoo_login {

public static void main(String[] args) throws Exception {

    FirefoxDriver fd = new FirefoxDriver();
    fd.manage().window().maximize();
    fd.get("http:yahoomail.com");
    Thread.sleep(1000);

    FileInputStream fs = new FileInputStream("E:\\Testing\\Testdata.xls");
    Workbook wb = Workbook.getWorkbook(fs);
    Sheet s = wb.getSheet(1);

    for (int r=0; r<s.getColumns();r++)
    {
        fd.findElement(By.name("login")).sendKeys(s.getCell(r,1).getContents());
        fd.findElement(By.name("passwd")).sendKeys(s.getCell(r,1).getContents());
        fd.findElement(By.name(".save")).click();
    }   

}

}
4

1 回答 1

0

@Aditya,您能否详细解释一下您的情况,您到底想做什么以及您目前的方法是什么。

无论如何,我从您的帖子中了解到,您想通过 excel 将用户名和密码传递给登录功能。您可以通过创建 excel 读取函数和使用 JXL api 来完成。有关更多详细信息,请查看此链接 Read Excel data using JXL

于 2014-09-21T12:14:58.660 回答