TaskTimedOut: Task timed-out waiting for element to be visible using: By(link text,***)

Hello Everyone,

When I run or validate a scripted browser,it mostly throws me task timed out error.
I have also increased the timeout,but didnt work.
Below is the line where am facing the issue -

.then( function(){return logger.log(19,“Wait For Element is Visible By.linkText(“0287 Test WI in E2E Performance Measure PA”)”,“TEST”),$browser.waitForAndFindElement(By.linkText(“0287 Test WI in E2E Performance Measure PA”),300000).then(e=>$browser.wait($driver.until.elementIsVisible(e)).then(e=>(assert(e),Promise.resolve(!0))))})

Below is the error i am facing -
Script execution failed: StaleElementReferenceError: stale element reference: element is not attached to the page document.

From: Task: Timed-out waiting for element to be visible using: By(link text, E2E Performance Measure PA)

NOTE - The element we are searching is present in the page.Recheck works sometimes.

Please help me resolve this issue since I am new to this tool.

Thanks in Advance!
New Relic Alm Team

Hey @RelicALM.New - can you share a link to the Synthetics Monitor that is failing? (Only NR Admins, or users listed in your account will have access to that link)

https://one.newrelic.com/launcher/nr1-core.explorer?pane=eyJuZXJkbGV0SWQiOiJzeW50aGV0aWNzLW5lcmRsZXRzLm1vbml0b3Itb3ZlcnZpZXciLCJlbnRpdHlJZCI6Ik1qZzVNakl4Tkh4VFdVNVVTSHhOVDA1SlZFOVNmRGM1WVRWak1HRXpMVGsxWXpBdE5HVmxPQzA1WW1Zd0xUQTNObUl4T1RGbE9XRTJOdyJ9&sidebars[0]=eyJuZXJkbGV0SWQiOiJucjEtY29yZS5hY3Rpb25zIiwiZW50aXR5SWQiOiJNamc1TWpJeE5IeFRXVTVVU0h4TlQwNUpWRTlTZkRjNVlUVmpNR0V6TFRrMVl6QXROR1ZsT0MwNVltWXdMVEEzTm1JeE9URmxPV0UyTnciLCJzZWxlY3RlZE5lcmRsZXQiOnsibmVyZGxldElkIjoic3ludGhldGljcy1uZXJkbGV0cy5tb25pdG9yLW92ZXJ2aWV3In19&platform[accountId]=2892214&platform[timeRange][duration]=1800000&platform[$isFallbackTimeRange]=true

@RelicALM.New

If we look at a recent monitor failure (here) - we can see the failure screenshot. There we see a list at which point the monitor has failed while looking for the text: 0387 Test WI

that list appears to be sequential - and in the most recent failure, that list shows from 0435 -> 0423.

So 0387 is not visible. That is where this monitor is failing. You may benefit from either:

  1. Add a line like below - to set the window size to something big enough for you to view the 0387 record:
.then( function(){return logger.log(1.5,"Set Window Size Width=1980 Height=1024","TEST 2"),browser.window().setSize(1980,1024).then(e=>e)})

This line should be popped in after line 25, so push the current line 26 down to 27 & this line will pop in between 25 & 27.

  1. Alter your script to look for a record that is within the currently visible window (between 0435 -> 0423)

  2. Execute a scroll in your script - to get the currently visible list to show number 0387 that you are looking for. You can do that with by:

    • open up the console in your browser and manually check what is a good position of x and y using window.scroll(x,y) and then set the position in the Synthetics script like so:
.then(function(){return logger.log(14.5,"Setting position to make the listing visible"),$browser.manage().window().setPosition(x, y).then(e=>e)})

This line should go before you are trying to click the 0387 listing. In your case, that’ll be between steps 14-15, lines 38-39 of your script.

1 Like

I have changed the link text to a point where it is visible and also added the co-ordinates before that.Still I see the same error sometimes.Please check the below monitor -

https://one.newrelic.com/launcher/nr1-core.explorer?pane=eyJuZXJkbGV0SWQiOiJzeW50aGV0aWNzLW5lcmRsZXRzLm1vbml0b3Itb3ZlcnZpZXciLCJpc092ZXJ2aWV3Ijp0cnVlLCJyZWZlcnJlcnMiOnsibGF1bmNoZXJJZCI6InN5bnRoZXRpY3MtbmVyZGxldHMuaG9tZSIsIm5lcmRsZXRJZCI6InN5bnRoZXRpY3MtbmVyZGxldHMubW9uaXRvci1saXN0In0sImVudGl0eUlkIjoiTWpnNU1qSXhOSHhUV1U1VVNIeE5UMDVKVkU5U2ZHWTVZemRpTVRCaExUVTJObVV0TkRRMU1pMWhNMlJoTFRjMU4yRmpZekEyWVRWbFpnIn0=&sidebars[0]=eyJuZXJkbGV0SWQiOiJucjEtY29yZS5hY3Rpb25zIiwiZW50aXR5SWQiOiJNamc1TWpJeE5IeFRXVTVVU0h4TlQwNUpWRTlTZkdZNVl6ZGlNVEJoTFRVMk5tVXRORFExTWkxaE0yUmhMVGMxTjJGall6QTJZVFZsWmciLCJzZWxlY3RlZE5lcmRsZXQiOnsibmVyZGxldElkIjoic3ludGhldGljcy1uZXJkbGV0cy5tb25pdG9yLW92ZXJ2aWV3IiwiaXNPdmVydmlldyI6dHJ1ZX19&platform[accountId]=2892214&platform[timeRange][duration]=1800000

Hi @RelicALM.New

I’m sorry for the delay here - my discuss.newrelic.com notifications clearly need some optimising :man_facepalming:

As for your script, I can’t say with certainty why this is happening, really I would need to have access to the page being monitored to better understand which locator methods would be most useful and how to get your script to run successfully.

Without actually having access, I can make a recommendation that you look here: https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/scripting-monitors/introduction-scripted-browser-monitors#locating-elements

You’ll find a few different locator methods - I suggest trying a few of those in the hopes that it can get your script running successfully.

1 Like