Iterate through array of elements

Quick sample script to iterate through an array for elements returned by findElements

var getData = function (element) {
element.getText().then(function(text){
  return console.log(text);
});
};

$browser.get('http://www.w3schools.com/html/tryit.asp?filename=tryhtml_table').then(function(){
  // Switch to iFrame
  $browser.switchTo().frame('iframeResult');
}).then(function(){
  // get elements of array
  return $browser.findElements($driver.By.xpath('/html/body/table/tbody/*/*')).then(function(elements){
  // iterate through array calling getData for each one 
    elements.forEach(getData);
    });
  });
6 Likes