1

String = There are 4 records in this list Here 4 is value of variable 'n'. I need to extract this value of variable from message displayed on web application using Selenium IDE. Much appreciated.

3
  • 1
    Not able to understand your question. Can you provide more details and code snippet of list. Commented Feb 10, 2016 at 11:28
  • On my web application, there is table which show records and it display message that "There are 4 records in the table". Now 4 is value of variable for number of records. I want to run loop in Selenium IDE to validate items in table for 4 rows of record. Therefore, i need to extract this 4 out of message display on web application. I hope i explains my question.
    – ian
    Commented Feb 11, 2016 at 1:52
  • if message is "There are 5 records in the table" i want to store 5 in my variable in selenium. If message is "There are 10 records in the table" i want to store 10 in my variable in selenium.
    – ian
    Commented Feb 11, 2016 at 1:56

2 Answers 2

2
  1. use storeText to store the text message
  2. echo to verify it
  3. use storeEval to extract the numeric value from text message string
  4. echo it and use it where required

Check example below for a sample solution.

storeText id=abcXYZabc myVar 
storeEval storedVars['myVar'].match(/\d+/); myExtractedNum 
echo ${myExtractedNum}



<tr>
    <td>storeText</td>
    <td>//xPath/xyz/div/div[3]/p[8]</td>
    <td>myVar</td>
</tr>
<tr>
    <td>echo</td>
    <td>${myVar}</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['myVar'].match(/\d+/)</td>
    <td>myExtractedNum</td>
</tr>
<tr>
    <td>echo</td>
    <td>${myExtractedNum}</td>
    <td></td>
</tr>
0
1
<tr>
    <td>storeText</td>
    <td>xpath of string</td>
    <td>string</td>
</tr>
<tr>
    <td>echo</td>
    <td>${string}</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['string'].match(&quot;are(.*)records&quot;)</td>
    <td>number</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>storedVars['number'][1]</td>
    <td>num</td>
</tr>
<tr>
    <td>echo</td>
    <td>${num}</td>
    <td></td>
</tr>
  • storeText | xpath of string | string => extracts the string
  • echo | ${string} => display string
  • storeEval | storedVars['string'].match("are(.*)records") | number => gets the substrings "are 4 records", 4
  • storeEval | storedVars['number'][1] | num => get second substring
  • echo | ${num} => prints the value you require
3
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review Commented Feb 11, 2016 at 7:09
  • @TESTasy - I have modified my answer to get the right value. Hope it helps Ian.
    – Sanchita
    Commented Feb 11, 2016 at 8:46
  • 2
    Maybe this piece of code does the job, but you need to explain it a bit. For example, see how TestingWithArif has written his answer. Commented Feb 11, 2016 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.