Hi,
I have list of keywords which i am trying to search on a website and then once i get the results , I am trying to iterate through max 6 items and click on them to open a modal and check if content is correct or not. Issue i am facing is findElemets always returns 1item inside the loop even though there are multiple items. Same works fine if keep findElements outside loop. Please find below code snippet
var keywords = ['a', 'b', 'c', 'd'];
$browser.get('url').then(function() {
keywords.forEach(function(item) {
return $browser.findElement($driver.By.xpath("selector")).sendKeys(item).then(function() {
return $browser.findElements($driver.By.xpath("selector")).then(function(elements) {
if (elements.length > 0) {
assert.equal(true, true);
} else {
assert.fail("Error in product seach by keyword " + item);
}
}.then(function() {
// click on search to open product listing
return $browser.findElement($driver.By.xpath("selector']")).click();
}).then(function() {
return $browser.findElements($driver.By.className("selector")).then(function(elements) {
// elements.length is always 1
}
})
}