I can watch execute_script()
run many many times in the AngularJS routed single page I'm testing since it seems a lot of the code uses execute_script()
to talk to the browser.
The specific call is:
driver.execute_script("return window.dataLayer")
Which works many times successfully.
But at some point, that same command receives a 404 from Selenium. I dug into the python selenium:
Deep in urllib3 it's POSTing this same as every other time:
ipdb> urlopen_kw
{'body': '{"script": "return window.dataLayer", "args": []}', 'request_url': 'http://127.0.0.1:51673/session/<sessionidxxx>/execute/sync'}
But at the same place in the test, suddenly the response from the request is:
ipdb> data
'{"value":{"error":"stale element reference","message":"stale element reference: stale element not found\\n (Session info: chrome=84.0.4147.105)","stacktrace":"#0 0x561877802d99 \\u003C
unknown>\\n"}}'
I'm on Ubuntu:
/usr/bin❯ chromium-browser --version
Using PPAPI flash.
Chromium 84.0.4147.105 Built on Ubuntu , running on Ubuntu 18.04
/usr/bin❯ chromedriver --version
ChromeDriver 84.0.4147.30
That ChromeDriver was found via: https://chromedriver.chromium.org/downloads/version-selection
Using pdb, I'm still perfectly able to use execute_script(<command>)
to interact with the page and everything on it. And the URL isn't changing and the page is not refreshing.
It just seems that somehow the specific window.dataLayer
(while still present and complete in the browser dev console) is "stale". Is it cached somewhere? In the webdriver? Is there a way to stop that?
The only connection I can make is that when I only used the dataLayer object for one evaluation it seems to NOT break. But I enhanced the code to look at the dataLayer in a loop (after acquiring it once). It would not immediately go stale. But after a larger interaction triggering XHR and other requests, suddenly it says it's stale. Very confusing.
I hope this is enough information for somebody to recognize what might be the cause.
Thanks much!