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

Popup help scripted browser


#1

Hello,

How to use conditional statement to find if pop is present and take action based on that in scripted browser?

I went to several threads but nothing worked for me. Here is what i tried…

function checkOverlay (step){
  var deferred = Q.defer();
  var element = $browser.findElement($driver.By.xpath("xxxxxxxxxx"))
  .then(function(element){
    if (element.length === true) {
    $browser.findElement($driver.By.xpath("XXXXXXXX")).click();
    console.log("Step 9: Closed popup Successfully");
  }
  else  {
    console.log("step 10: No popup found")
  }
})
  return deferred.promise;
};
checkOverlay(7)

the above code returns with error xpath (variable) not found. To my understanding if variable is not found, script should exit with console log pop not found…

What am i missing, any insight will be of huge help.


#2

Hi @Karthick.N - In the true part of your if statement, you need deferred.resolve(); after the console.log

if (element.length === true) {
    $browser.findElement($driver.By.xpath("XXXXXXXX")).click();
    console.log("Step 9: Closed popup Successfully");
    deferred.resolve();
}

#3

@Karthick.N - was Stefan’s comment helpful for you?

Let us know if you’re still running into trouble with this.