-2

How to write for-loop for log in into yahoo for multiple customers the inputs given in excel. I want for selenium data driven test.

Here i need values from column B not from column A & my rows needs to be incremented.

So how to write the for loop

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

password              >>>>123456

username              >>>>ABC@yahoo.com

password              >>>>123456

I have tried the below code,

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

}

}
ngrashia
  • 9,869
  • 5
  • 43
  • 58
Aditya
  • 1
  • 1
  • 3

1 Answers1

0

@Aditya, Can you please explain your scenario in detail, what exactly you want to do and what is your current approach.

Anyway, What I understand from your post is that you want to pass username and passowrd to login function through excel. You can do it by creating excel read function and using JXL api. For more detail, check this link Read Excel data using JXL

Raj
  • 664
  • 7
  • 23
  • Yes I want to read the values from excel for 2 different users. for that i need a for-loop for that implementation. As per above my code the values from excel sheet are entered side by side. like : pswd123456 for both userid field and password field, but i want only mailid in userid field and "123456" password to be entered in pasword field – Aditya Sep 21 '14 at 13:00
  • @Aditya. I didn't understand what you mean by side by side entering of data. Have you Checked the link [Read Excel data using JXL] https://docs.google.com/document/d/1p9E_Ob9HevUVdOXOOylLMgqL7J_KTxygHj_f8PJr4lg/edit?pli=1 – Raj Sep 21 '14 at 13:56
  • @Aditya. In the above shared link you can find same scenario where both email id and login id is being passed from excel. Depending on your requirement, you can modify your excel data or function code. Hope it will help you. – Raj Sep 21 '14 at 13:58