1

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 compare 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 command 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.

2 Answers 2

2

Variable of storeXXX result is set to storedVars.
Try to follows.

storeText id=numAndString text 
storeEval storedVars['text'].match(/^\d+/); num 
echo ${num}
Sign up to request clarification or add additional context in comments.

1 Comment

removing ^ sign from storedVars['text'].match(/^\d+/); worked for me.
0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.