stale element reference: element is not attached to the page document - how can I make the current page the current page document as I have gone to a new page

4,555 views
Skip to first unread message

jloyzaga

unread,
Jun 14, 2016, 12:12:58 AM6/14/16
to robotframework-users
Documentation:

Waits until element specified with `locator` is not visible.

Start / End / Elapsed:20160614 14:04:52.170 / 20160614 14:05:02.254 / 00:00:10.084
00:00:00.249KEYWORD Selenium2Library . Capture Page Screenshot
Documentation:

Takes a screenshot of the current page and embeds it into the log.

Start / End / Elapsed:20160614 14:05:01.999 / 20160614 14:05:02.248 / 00:00:00.249
14:05:02.248INFO Then I want to wait till the new image in a new page is visible I do this but its in a new page | | wait until element is visible | xpath=html/body/div[1]/div[3]/div[1]/div/div[3]/div[1]/div[1]/div/div/div[3]/div/div/button
14:05:02.254FAILStaleElementReferenceException: Message: stale element reference: element is not attached to the page document (Session info: chrome=51.0.2704.84) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)

Michał Robaszewski

unread,
Jun 15, 2016, 7:21:42 AM6/15/16
to robotframework-users
Hi
With that errors work only retry :)
Wait Until Keyword Succeeds 2x 300ms wait until element is visible  xpath

Stale Element References is basic Selenium Error from site with heavy JS presence .
Sacond basic error : Element not found in the cache ...
Its pain in the *** :)

Here is more detail definition from Stack
"

First of all lets be clear about what a WebElement is.

A WebElement is a reference to an element in the DOM.

A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated.


When this happens the reference to the element in the DOM that you previously had becomes stale and you are no longer able to use this reference to interact with the element in the DOM. When this happens you will need to refresh your reference, or in real world terms find the element again.

jloyzaga

unread,
Jun 15, 2016, 4:21:16 PM6/15/16
to robotframework-users
so is that a keyword? Wait Until Keyword Succeeds 2x 300ms wait until element is visible  xpath

Michał Robaszewski

unread,
Jun 16, 2016, 3:55:43 AM6/16/16
to robotframework-users
Keyword :
 Wait Until Keyword Succeeds
Params
1) Retry - how many times or how long
2) retry interwal - how often lunch keyword
3) name- keyword to retry and it params.

def :" Runs the specified keyword and retries if it fails."
When at first you catch Stale element error this keyword retry your wait until which can refresh reference to WebElement.

All of that info is in BuiltIn documentation.
Spent some time and analyse keywords from BuiltIn library.

J Wipf

unread,
Jun 16, 2016, 6:26:04 AM6/16/16
to robotframework-users
Another option would be to use a Wait Until keyword from Sel2Lib for something you know will load on the page after the item your are desiring access too (ideally last item to load). I don't know of a way to not have some sort of wait though, either a WUKS or Wait Until.
Reply all
Reply to author
Forward
0 new messages