user3782636
user3782636

Reputation: 83

Cannot Instantiate class error - Selenium WebDriver using testng

I want to pass an integer variable to web element using Sendkey function and i'm getting that integer vaiable from another class and passing through a method and calling in sendkey funciton but getting type casting error. I'm very new to selenium. Please help me to improve my selenium knowledge wider. Attached screen shot for your better understand.

public static WebElement setQuantityPage(WebDriver driver,int **individual_units**,int noOFCaseUnit, int noOfBox)
{
    Select  packType = new Select(driver.findElement(By.xpath(".//*[@id='fba-core-view-meta-data-pkg-type']/**strong text**dl/dd[1]")));
    packType.selectByVisibleText("Individual products");
    String type=packType.toString();
    if(type.equalsIgnoreCase("Individual products"))
    {
        driver.findElement(By.xpath(".//*[@id='batch-update-number-cases']")).sendKeys(**individual_units**);
    }
I'm asking for above bold letters.
    else
    {

    }
    return element;
}

Upvotes: 0

Views: 344

Answers (1)

optimistic_creeper
optimistic_creeper

Reputation: 2799

Sendkeys methods takes only CharSequence as it's parameter. But your are passing an integer as an argument. That's why you are getting a type casting error. Replacing

driver.findElement(By.xpath(".//[@id='batch-update-number-cases']")).sendKeys(individual_units);

with

driver.findElement(By.xpath(".//[@id='batch-update-number-cases']")).sendKeys(individual_units+"");

or

driver.findElement(By.xpath(".//[@id='batch-update-number-cases']")).sendKeys(String.valueOf(individual_units));

will resolve your problem.

Upvotes: 1

Related Questions