How to extract number from string using "storeEval" - Selenium IDE Tutorial

I posted other posts too for "storeEval". Click here to view more tutorials of selenium IDE "storeEval" command. In software testing using selenium IDE, many times you needs to verify or compare the number of records list during activity like searching, adding or deleting records. Generally, record count displayed on
page like "24500 records found.", "24500 records available." or  "24500 orders found." etc. Now if you store this full string to compare records then it is not possible. For comparing numbers, you need to extract numeric value from string. Let me give you example of extracting number from string.

New Test
store24500 Records Found.string
gotoIfstoredVars['number'] >= 225greater
echoRecords are less than expected...
echoRecords are greater than expected...

Run above script in selenium IDE. Here, "storeEval" will extract number '24500' from string '24500 Records Found.' using javascript statement "storedVars['string'].match(/^\\d+/);". Then i can use its value to compare with conditional command "gotoIf".

1 comment:

  1. Hi,
    I have a problem similar to this one.
    What do I have to do if there's some kind of string in front of the number I want to extract?
    My string is '(XX)' where XX is a number.
    I can extract the number from 'XX)' but not from '(XX'.
    I tried "storedVars['string'].match(\d+//^\);" for '(XX' but it says "illegal character".