I have a x-path
in selenium which contains dynamic value as p01 to p15. If So, if I increment it should pass like 02,03,04,05,06,07,08,09,10,11,12 like this.
But i am unable to find a code to increment a value with 0 prefix.
I have a x-path
in selenium which contains dynamic value as p01 to p15. If So, if I increment it should pass like 02,03,04,05,06,07,08,09,10,11,12 like this.
But i am unable to find a code to increment a value with 0 prefix.
I'm not sure the complete nature of the request because there is some information missing but you can adding leading zeroes to an integer in java with String format.
public class Main {
public static void main(String[] args) {
String formatted = String.format("%02d", 5);
String formatted1 = String.format("%02d", 11);
System.out.println(formatted);
}
}
You could use a simple function to do it and then use it in your loop:
public getPathValue(int x)
{
return x < 10 ? "p0" + x : "p" + x;
}
If we call it with value 1 => getPathValue(1)
as return value we will have p01
.
If we call it with value 10 or larger => getPathValue(10)
as return value we will have p10
.