Tuesday, March 20, 2012

Javascript to strip or replace characters

In Selenium IDE, I wanted to verify one amount was greater than another. The amounts were in dollar/comma format ($3,400.00), so I needed to strip the dollar sign and comma before comparing the values.

Strip the dollar sign from variable1:
storeEval storedVars['variable1'].replace(/\$/g,'') dx

Strip the comma from 'dx' (created when stripping the dollar sign in previous step):
storeEval storedVars['dx'].replace(/\,/g,'') x

Verify that 'x' is greater than 'y'
verifyEval storedVars['x'] > storedVars['y'] true