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.
-
1Not able to understand your question. Can you provide more details and code snippet of list.– TestingWithArifCommented 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.– ianCommented 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.– ianCommented Feb 11, 2016 at 1:56
Add a comment
|
2 Answers
- use storeText to store the text message
- echo to verify it
- use storeEval to extract the numeric value from text message string
- 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>
<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("are(.*)records")</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
-
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.– SanchitaCommented Feb 11, 2016 at 8:46
-
2Maybe 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