Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Iterate through array of elements

synthetics-script
developer

#1

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);
    });
  });

$browser.findelement in a loop