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


#1

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(By.id(“logInEmail”), DefaultTimeout);
})
.then(function (el) {
el.clear();
el.sendKeys(“testuser”);
})

Link to the failing Alert: https://synthetics.newrelic.com/accounts/874863/monitors/fe237032-94ab-4f29-9685-91529551c7b6/results/969183fb-432d-4375-923a-9b7a287ca7ef?view=timeline&tw[start]=1542239751.154&tw[end]=1542241551.154


#2

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:


#3

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


#4

@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:


#5

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!


#6

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


#7

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?

https://synthetics.newrelic.com/accounts/874863/monitors/5a13c78a-39c1-4aa7-ac60-b1ec46b29135/results/334d135c-eacf-45f8-ab0d-023419495115?view=script-log&tw[start]=1543502711.76&tw[end]=1543506311.76


#8

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:

$browser.wait($driver.until.elementIsVisible($browser.findElement(By.id("logInEmail"))));

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


#9

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.


#10

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: