I want to get all values from a column in the table on webpage until the column does not contain an element, sum values and return the sum as a promise.
TablePage.prototype.getPriceValuesFromList = function () {
for (number = 1; number < 100; number++) {
var locator = '//*[@id="root"]/main/section/table/tbody/tr[' + number + ']/td[3]/div[2]';
browser.findElement(By.xpath(locator)).then(function (success) {
if (success) {
var locator = '//*[@id="root"]/main/section/table/tbody/tr[' + number + ']/td[3]/div[2]';
return element(By.xpath(locator)).getText().then(function (text) {
numb = text.replace(/,/g, '');
numb = numb.replace(/\$/g, '');
numb = numb.replace(/\./g, '');
prices[number] = parseInt(numb);
console.log(prices[number]);
var sum = prices.reduce(function(a, b) { return a + b; }, 0);
console.log(sum);
return sum
})
}
else {
break;
}
})
}
};
I get : "Illegal break statement"
How to actually do it?
Do I have to define "locator" 2 times?