Selenium error element is not attached to the page document.
search cancel

Selenium error element is not attached to the page document.

book

Article ID: 267405

calendar_today

Updated On:

Products

DX SaaS

Issue/Introduction

Receiving the below error in my application. what is could be:

Script failed at step 8: stale element reference: element is not attached to the page document.

 

 

Environment

Release : SAAS

Cause

The error means that the <body> element was not attached. This is known to happen from time to time if the command is executed in a certain phase of loading of a new page. See the documentation link in the error message for details.

Resolution


The workaround that is known to work is to explicitly specify the element to perform the search in. You can pick any element on the page as long as it or it's child contains the expected text string.

For example, in this case the page has a <div id='root'> element. The step 8 could become:
command: waitForTextPresent, target: 'Nuevos incidentes masivos', value: 'id=root' 

You also put a waitForPageToLoad or a pause before that step.

In this script the step 8 is: command: waitForTextPresent, target: 'Nuevos incidentes masivos', value: ''

The 'value' indicates which element is used for the search. Empty value means that the <body> element is used. (value: 'tag=body')
The error means that the <body> element was not attached. This is known to happen from time to time if the command is executed in a certain phase of loading of a new page. See the documentation link in the error message for details.

The workaround that is known to work is to explicitly specify the element to perform the search in. You can pick any element on the page as long as it or it's child contains the expected text string.

For example, in this case the page has a <div id='root'> element. The step 8 could become

command: waitForTextPresent, target: 'Nuevos incidentes masivos', value: 'id=root'