0

My excel sheet has 2 columns Username& Password with different 5 records, I want to read and pass data from this excel and want to open 5 chrome browsers with these 5 users. How can this achieve?

1 Answer 1

0

Here is a little something with Selenium, Java and JXL library to get you started,

try {
    Workbook workbook = Workbook.getWorkbook(new File(System.getProperty("user.dir") + "//file.xls"));
    Sheet sheet = workbook.getSheet(0);
    
    WebDriver[] driver = new WebDriver[sheet.getRows()];

    System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "//geckodriver");
    System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
    
    for (int row = 1; row < sheet.getRows(); row++) {
        String username = sheet.getCell(0, row).getContents();
        String password = sheet.getCell(1, row).getContents();
        driver[row] = new FirefoxDriver();
        driver[row].manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver[row].get("https://www.google.com");
        driver[row].manage().window().maximize();
        System.out.println("Username: " + username);
        System.out.println("Password: " + password);
        Thread.sleep(2000);
        driver[row].close();
    }
    
    Thread.sleep(5000);
    for (int i = 1; i < sheet.getRows(); i++) {
        driver[i].close();
    }
} catch (Exception e) {
    e.printStackTrace();
}

This is what my spreadsheet (excel sheet) looks like,

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.