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

Getting StaleElementReferenceError a few times a day


I’m getting the following error periodically (once or twice a day):
Browser script execution FAILED.
StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=44.0.2403.157)

The Stale Element error is on the logInEmail element

This is the first part of the code that is used:
$browser.getCapabilities().then(function () { })
.then(function() {
// Step 1
log(1, ‘$browser.get(“xxx”)’);
return $browser.get(“xxx”);
.then(function() {
// Step 2
log(2, ‘setElementText “logInEmail”’);
return $browser.waitForAndFindElement(“logInEmail”), DefaultTimeout);
.then(function (el) {

Link to the failing Alert:[start]=1542239751.154&tw[end]=1542241551.154


Hi @atrace, It looks like your monitor version is an old one, Monitor version 0.2.2. waitForAndFindElement() is a pretty new custom function so it may not work as expected all the time with an older monitor version. I’ve been testing the script for a while with a new monitor and hasn’t failed so far, so this might be worth trying first. I’ll update here if I don’t see any failures after 24 hours or so aswell :slight_smile:


Ok, thanks for testing! Is it recommended to periodically update the monitor version?


@atrace not necessarily no, if your monitor is working and you are using functions from the documentation for that version there’s really no need to update. You can find the version number in the Settings tab of the monitor.

Because the older versions of monitors use an older version of Chrome, if Chrome deprecate a feature then the only way to use it is with an older version of the monitor.

Currently, the only way for a customer to upgrade a Monitor is to create a new one, though there is a similar Feature Idea that you could vote on and ad your use-case to if you want.

Hope that helps :slight_smile:


Thanks, I had a new version of the monitor going over the holiday weekend and didn’t see any false positives so we’ll switch over. Thanks again for your help!


That’s great @atrace delighted to hear it :smiley:


I spoke to soon! It’s definitely less frequent but it does look like the same error. Is there a better/preferred way to reference the input field?[start]=1543502711.76&tw[end]=1543506311.76


Hi @atrace, generally id is the best selector. Judging by the screenshot for one of the failures it looks like the page actually hadn’t loaded fully yet, so the loginEmail element is not selectable in this case. You could try a $browser.sleep() before it, or better yet wait until it is visible with the following:


Just bear in mind that the page taking longer to load may be representative of real user experience at the time :slight_smile:


Ok, so a wait with the nested util.elementIsVisible is a better idea than using waitForAndFindElement? For all the waitForAndFindElements I had a timeout of 10s set which I thought would have waited at least 10s for it to be found and available. Based on that failed example you linked in your reply less than 2s had passed.


Hi @atrace, it’s not always better but if the issue is the element is rendered it’s just not clickable then using $browser.wait($driver.until.elementIsVisible() may be better her, it’s worth trying anyway. The waitForAndFindElement() will only wait until the element has been rendered, so in this case it was but it is the click() function that actually failed in this case because the element was not visible. Hope this helps :slight_smile: