Skip to content Skip to sidebar Skip to footer

Selenium Split Date String Working Example?

I'm trying to split a date string (04.05.2012) into 3 sub-strings for later string manipulation. When I run the below code in a regular javascript editor (in Eclipse), it works. In

Solution 1:

Try

<tr><td>storeEval</td><td>day = storedVars.dsplit1[2]</td><td>dsplit2</td></tr>

instead of

<tr><td>storeEval</td><td>day = '${dsplit1}'[9]</td><td>dsplit2</td></tr>

it will give you a year (2012). storedVars.dsplit1[0] and storedVars.dsplit1[1] will give you 04 and 05 correspondingly. Or you can use simple storeEval | dList[2] | dsplit2. In this case you can use getEval | dList = '${flight_date}'.split('.'); instead of storeEval | dList = '${flight_date}'.split('.'); | dsplit1

Solution 2:

Is it treating . as any character as in a regular expression?

Try escaping it

'${flight_date}'.split('\.');

or

'${flight_date}'.split(/\./g);

Post a Comment for "Selenium Split Date String Working Example?"