admin管理员组文章数量:1022864
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
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
本文标签: javascriptExtracting Number from a string using Selenium IDEStack Overflow
版权声明:本文标题:javascript - Extracting Number from a string using Selenium IDE - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745550830a2155625.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论