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

Conditional check for element



Here is a sample script that shows how to check for the presence of an element to determine which page loaded, helpful for if your site intermittently loads different versions or displays popups. It’s necessary to use the isElementPresent instead of the findElement because findElementwill stop the script with an error if the element if not found. The Q library is used to promise-ify the two functions called so they can be properly sequenced or inserted into another script to call the checkSite function multiple times.

var Q = require('q');
function randomInt (low, high) {
    return Math.floor(Math.random() * (high - low) + low);

function getSite(random) {
var deferred = Q.defer();
  if(result == 1) {
  } else {
return deferred.promise;

function checkSite(){
var deferred = Q.defer();
var element = $browser.isElementPresent($"search-start"))
  if(elem === true){
    console.log("click search element");
  else {
    console.log("loaded google site");
return deferred.promise;

var result = randomInt(1,10);
console.log("Random Int was "+result);


FORESEE Popup Workaround