For one of my protractor script. I want to fetch the value of an element.
Here is the DOM setup:
<h5 class="ng-binding ng-scope" ng-if="editor.special.stock_number !== ''">
<b>Stock Number:</b>
72850
</h5>
I want to fetch the value of Stock Number:
I tried using getText, but it just printed out the Stock Number:
this.get_stock_number = () => {
let stockNumber = stock_number.getText();
stockNumber.then((text) => {
console.log("Stock Number is: " + text);
});
};
I also tried using getAttribute but it is returning null:
this.get_stock_number = () => {
let stockNumber = stock_number.getAttribute('Stock Number:');
stockNumber.then((text) => {
console.log("Stock Number is: " + text);
});
};
I really need this thing to be sorted out. I am kind of stuck here. Any help will be much appreciated, Thanks.
You can try:
h5element.getText()
so it can return Ex:
<b>Stock Number:</b> 72850
let text = `<b>dsadsad</b> 320301`; let numberPattern = /\d+/g; let results = text.match(numberPattern); if (results != null) { let number = results[0]; console.log(number); }