I've looked at dozens of answers to this question, and tried all of them, but can't get any of them to work. I'm sure it's something very simple, but here's what I'm trying to do;
I need to extract a numeric value from a string, then pare it to see if it is greater than or equal to a number. I am using Selenium IDE.
The string is simple XXX Total matches
where XXX
is the number. I've stored this string using storeText
, storing it in a variable named appropriately enough, String.
I then run an echo
mand to display "String" to make sure I've got that part correct, and it displays the "XXX Total matches" string as expected.
I have tried several methods mentioned on extracting the number part of the string, including regexp, javascript, etc.
The one that "seems" to work is storeeval | String=String.slice(0, 2); | Number
, but when I try to echo Number, it shows nothing.
I've tried
javascript{(${String}.match(/\\d+/))}
javascript{parseInt(${String}, 10);}
javascript{parseInt(${String})}
But when I try those, I get an error in selenium IDE
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2531
I'm sure it's probably a basic newbie mistake, but I can't figure out what I'm doing wrong.
I've looked at dozens of answers to this question, and tried all of them, but can't get any of them to work. I'm sure it's something very simple, but here's what I'm trying to do;
I need to extract a numeric value from a string, then pare it to see if it is greater than or equal to a number. I am using Selenium IDE.
The string is simple XXX Total matches
where XXX
is the number. I've stored this string using storeText
, storing it in a variable named appropriately enough, String.
I then run an echo
mand to display "String" to make sure I've got that part correct, and it displays the "XXX Total matches" string as expected.
I have tried several methods mentioned on extracting the number part of the string, including regexp, javascript, etc.
The one that "seems" to work is storeeval | String=String.slice(0, 2); | Number
, but when I try to echo Number, it shows nothing.
I've tried
javascript{(${String}.match(/\\d+/))}
javascript{parseInt(${String}, 10);}
javascript{parseInt(${String})}
But when I try those, I get an error in selenium IDE
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2531
I'm sure it's probably a basic newbie mistake, but I can't figure out what I'm doing wrong.
Share Improve this question edited Aug 7, 2012 at 7:04 Rohit Ware 2,0021 gold badge15 silver badges29 bronze badges asked Aug 6, 2012 at 19:36 KlendathuKlendathu 7932 gold badges12 silver badges20 bronze badges2 Answers
Reset to default 2Variable of storeXXX result is set to storedVars.
Try to follows.
storeText id=numAndString text
storeEval storedVars['text'].match(/^\d+/); num
echo ${num}
You can split that number string by below code -
store | XXX Total matches | string
store | 0 | delimiter
store | javascript{storedVars['string'].split('Total')[storedVars['delimiter']]} | number
echo | ${number}
Result - XXX