Protractor:Is 可以仅打印包含数字和字符的元素中包含的数字
Protractor:Is it possible to print only the numbers contained in an elements that contains both numbers and characters
我是量角器的新手,我正在尝试仅检索包含在以下元素中的数值
<div class="balances">
<h3>Total Balance: EUR 718,846.67</h3>
</div>
我能够检索整个文本,但希望能够通过我的页面对象文件打印出“718,846.67”(或者应该是 718846.67)
checkFigures (figures) {
browser.sleep(8000);
var checkBalance = element.all(by.css('balances'));
checkBalance.getText().then(function (text) {
console.log(text);
});
}
我在有人发布类似问题时遇到了这个问题,但我不知道如何实施它,甚至不知道它在做什么
function toNumber(promiseOrValue) {
// if it is not a promise, then convert a value
if (!protractor.promise.isPromise(promiseOrValue)) {
return parseInt(promiseOrValue, 10);
}
// if promise - convert result to number
return promiseOrValue.then(function (stringNumber) {
return parseInt(stringNumber, 10);
});
}
这只是一道 javascript 题,使用 replace
和正则表达式即可轻松完成。这将从字符串中删除所有非数字。根据需要更改正则表达式。
checkFigures (figures) {
browser.sleep(8000);
var checkBalance = element.all(by.css('balances'));
checkBalance.getText().then(function (text) {
console.log(text.replace(/\D/g,''));
});
}
我是量角器的新手,我正在尝试仅检索包含在以下元素中的数值
<div class="balances">
<h3>Total Balance: EUR 718,846.67</h3>
</div>
checkFigures (figures) {
browser.sleep(8000);
var checkBalance = element.all(by.css('balances'));
checkBalance.getText().then(function (text) {
console.log(text);
});
}
我在有人发布类似问题时遇到了这个问题,但我不知道如何实施它,甚至不知道它在做什么
function toNumber(promiseOrValue) {
// if it is not a promise, then convert a value
if (!protractor.promise.isPromise(promiseOrValue)) {
return parseInt(promiseOrValue, 10);
}
// if promise - convert result to number
return promiseOrValue.then(function (stringNumber) {
return parseInt(stringNumber, 10);
});
}
这只是一道 javascript 题,使用 replace
和正则表达式即可轻松完成。这将从字符串中删除所有非数字。根据需要更改正则表达式。
checkFigures (figures) {
browser.sleep(8000);
var checkBalance = element.all(by.css('balances'));
checkBalance.getText().then(function (text) {
console.log(text.replace(/\D/g,''));
});
}