1

As I'm new to selenium, I'm trying to read data from excel sheet, format is .xlsx... The issue is I'm unable to pass the uName and pWord values here. I'm using Eclipse ide(Galileo), jdk 1.7..Using POI libraries from Apache.

Here below is the coding, please suggest me. Thanks much in anticipate.

public class TestDataExcl {

/**
 * @param args
 * @throws Throwable 
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    TestDataExcl tDataObj = new TestDataExcl();
    ArrayList<String> uName = autoInputFromList(0);//Ive tried as ArrayList uName = autoInputFromList(0)..
    ArrayList<String> pWord = autoInputFromList(1);
    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.facebook.com/");
    driver.findElement(By.id("email")).sendKeys(uName);//Error as:The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (ArrayList<String>)
    driver.findElement(By.id("pass")).sendKeys(pWord);//Same as the abover error, it is not recognizing uName, pWord..
    //tDataObj.autoInputFromList(0);
}
    //-------------------------------Reading Data From Excel File-----------------------------//
    public static ArrayList<String> autoInputFromList(int colNo) throws Exception{
        String filePath = "D:\\firstFile.xlsx";
        FileInputStream fisObj = new FileInputStream(filePath);
        XSSFWorkbook wbObj = new XSSFWorkbook(fisObj);
        XSSFSheet shObj = wbObj.getSheet("Sheet1");
        //Sheet shObj = wbObj.getSheetAt(0);
        Iterator<Row> rowIt = shObj.iterator();
        //<Row> int i = 0;
        ArrayList<String> list = new ArrayList<String>();
        rowIt.next();
        while(rowIt.hasNext()){
            list.add(rowIt.next().getCell(colNo).getStringCellValue());
        }System.out.println("List::"+list);
        return list;
    }

}

3 Answers 3

1

sendKeys() takes String type arguments, not the List.

Sign up to request clarification or add additional context in comments.

Comments

1

Since, your autoInputFromList() method returning an ArrayList of String type, so may get first item and assign it to uName & pWord respectively as below:

    String uName = autoInputFromList(0).get(0);
    String pWord = autoInputFromList(1).get(0);

Comments

0

sendKeys method takes String or array of String (String[]) as argument.

You can either pass your value as a String or you can convert ArrayList to String[].

driver.findElement(By.id("email")).sendKeys(uName.toArray(new String[0]));

If you are using java 8 :

driver.findElement(By.id("email")).sendKeys(uName.stream().toArray(String[]::new));

1 Comment

@Johny: Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.