0

I have a string of chars and integers which I am splitting to take out the negative integer value and then check if the value is negative, then do something inside if block. Code sample is as below:

java.util.Iterator<WebElement> i = elements.iterator();
while (i.hasNext()) {
    WebElement element = i.next();
    String str = element.getAttribute("name");
    System.out.println(str);
    String[] arrOfStr = str.split("_");
    System.out.println(arrOfStr);
    long res = Integer.parseInt(arrOfStr[1]);
    System.out.println(res);

    if (res < 0) {
        System.out.println("Inside if");
        System.out.println(data);
        Thread.sleep(10000);
        Select selectBox = new Select(element);
        selectBox.selectByVisibleText(data);
    }
MC Emperor
  • 22,334
  • 15
  • 80
  • 130
Abhinay Kumar
  • 57
  • 1
  • 7

1 Answers1

0

You are trying to parse in Integer for input string: “XYZ_-1556021952300”. Since there is character which cannot be parse into number. So you are getting this exception.

May be because of the following code you are facing this issue.

long res = Integer.parseInt(arr0fStr[1]);

Change this line to something like this:

String res = arrOfStr[1];