image
I am trying to read numbers in brackets '()' using selenium
The HTML code is
<span class="refinement-count"> (14)</span>
I am trying to read numbers between span.
Using selenium, values in the brackets are stored in a string. After reading the values, I want to add all these values. I used the split function and parsed it into an integer but Integer.parseInt()
is throwing the following exception:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
Here the code:
public static void convert(String s){
int sum=0;
String str[]=s.split("[()]+");
int[] numbers=new int[str.length];
for (int i = 0; i < str.length; i++)
{ //System.out.println(str[i]); --checked here, printing normal integers
numbers[i]=Integer.parseInt(str[i].trim());
sum=sum+numbers[i];
}
System.out.println("the sum of products is "+sum);
}
Using try-catch()
block the exception can be caught but output is not desirable.
Help
MODIFIED
When starting the loop from 1, it is printing/output
the sum of products is 14
the sum of products is 8
the sum of products is 8
the sum of products is 6
the sum of products is 4
the sum of products is 3
the sum of products is 2
the sum of products is 2
the sum of products is 1
the sum of products is 1
the sum of products is 1
the sum of products is 1
the sum of products is 1
the sum of products is 1
the sum of products is 1
Still there sum is not working