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

getText() result processing with Synthetics

synthetics-script

#1

Best way to compare multiple values from .getText()?

I am attempting to extract a text value from a set of fields in a web page so that I can find the highest value in the resulting list with WebElement.getText().

Expectation

The order of operations is intended to be something along the lines of:

// load site
// login to site
// display menu containing options
// iterate over list of selectable options
// ??? 
// find the option with the highest value
// click the select box found in the previous operations

Current Attempt

My most recent failed attempt looks like this:

$browser.get('https://apage.ontheweb')
  .then( . . . )
  .then(function(){
    return $browser.wait(
      until.elementsLocated(By.css('[class="selector"]'))
    );
  })
  .then(function*(filters){
    var count = 0;
    var greatestAssest = 0;
    var selectedFilter = 0;
    for (var filterKey in filters) {
      var numberAssets = 0;
      numberAssets = filters[filterKey].getText().then(function(text){
        return text;
      });
    }
  });

numberAssets remains 0.

Other Notes

I’ve tried all manner configurations to make this work but I just can’t get the value from the .then block after getText() to a place where it can impact the rest of the script. The thing that’s giving me trouble is persisting the value across iterations of the loop for comparison. Is there a way to do this?


#2

Hi, @Xander.Harris: You will have to declare the variable outside your function:

// declare variable here
var numberAssets = 0;

$browser.get('https://apage.ontheweb')
  .then( . . . )
  .then(function(){
    return $browser.wait(
      until.elementsLocated(By.css('[class="selector"]'))
    );
  })
  .then(function*(filters){
    var count = 0;
    var greatestAssest = 0;
    var selectedFilter = 0;
    for (var filterKey in filters) {
      return filters[filterKey].getText().then(function(text){
        // increment numberAssets 
        numberAssets++;
      });
    }
  }).then(function(){
    console.log(numberAssets);
  });