Assert cannot be able to find value because it's expecting a String but an integer is present instead. How can I be able to convert this String to an integer.

I tried using Integer.parseInt(number) but it is ignored.

@Then("^User assert \"([^\"]*)\" and \"([^\"]*)\"$")
public void userAssertAnd(String Qty, String Price)  {
String Quantity = driver.findElement(By.xpath("//tr[@class='GEHR2AJDIL']/td[8]/div/input[@class='form-control']")).getText();
AssertJUnit.assertEquals(Quantity, Qty);

String modifierPrice = driver.findElement(By.xpath("//tr[@class='GEHR2AJDIL']/td[9]/div/input[@class='form-control GEHR2AJDHI']")).getText();
AssertJUnit.assertEquals(modifierPrice, Price);
  • "I tried using Integer.parseInt(number) but it is ignored." what do you mean under "ignored"? And in which line do you experience the issue? As it seems from your code you compare String to String. There should not be type mismatches
    – Alexey R.
    Commented Jan 29, 2018 at 15:24
  • 1
    Also please do not start variable names from capital letters. There is a convention in Java world to name only Types from uppercase, variables should start from lowercase.
    – Alexey R.
    Commented Jan 29, 2018 at 15:27
  • I'm getting error: java.lang.AssertionError: expected:<> but was:<120> and I also tried String Quantity = String.valueOf(driver.findElement(By.xpath("//tr[@class='GEHR2AJDIL']/td[8]/div/input[@class='form-control']")).getText()); and the same error persists Commented Jan 29, 2018 at 15:31
  • 1
    It is not connected with whether you convert value to int or not. There are two strings one of which is empty. You need to do some debugging to know why that happens
    – Alexey R.
    Commented Jan 29, 2018 at 15:37

1 Answer 1


To get the string value of an int, you can use: String.valueOf(int)

Your Answer

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

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