Reading Data from Excel Sheet in Selenium WebDriver

1.1k views Asked by At

I am Using Selenium WebDriver and reading Data from a excel sheet that contains

Username and Password but the problem is this sheet contains both numeric Values and String Values due to which its throwing error:

Cannot get a STRING value from a NUMERIC cell

Username: rainrrr , shamz, tabraiz

Password: rainrrr ,123456,123456

Please Help

public void AdminLogin(String UserName, String Password) throws Exception
{

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\amomin\\Desktop\\selinium\\chromedriver.exe");
     driver =new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    driver.get("My Path");

    driver.findElement(By.xpath(".//*[@id='UserName']")).sendKeys(UserName);

    driver.findElement(By.xpath(".//*[@id='Password']")).sendKeys(Password);

    driver.findElement(By.xpath(".//*[text()='Submit']")).click();

    Thread.sleep(5000);


    Assert.assertTrue(driver.getTitle().contains("Dashboard - RainMaker"),"Login Fail");

    System.out.println("User Login Successfully");

}
public Object[][] LoginData()
{


    libDDT config=new libDDT("C:\\Users\\amomin\\workspace\\DataDrivenTest\\TestData\\TestData.xls");
    int rows=config.getRowCount(0);

    Object[][] data = new Object[rows][2];

    for(int i=0;i<rows;i++)
    {

        data[i][0]=config.getdata(0, i, 0);
        data[i][1]=config.getdata(0, i, 1);

    }

    return data;
}   
1

There are 1 answers

0
Girish Bellamkonda On BEST ANSWER

Try this by saving Numeric values in text format.

If the string is starting with number, in excel, format data as text by prefixing numeric value with single quotation ('). Ex: 123 as '123