I have thousands of tests running every day through selenium grid on BrowserStack.com, each using dozens of element references to manipulate our test web site. So with about 100,000 element manipulations per day, of course we see those periodic StaleElementReferenceExceptions. I use the standard strategies, wrapping webdriver actions in routines that automatically re-acquire the element reference and continue on. My tests run great in Windows and macOs environments, on all browsers.
But now I need to run these tests in iPad environments, using BrowserStack’s capabilities to automate browsers on real devices. There’s the normal expected issues with using a new browser or a new environment, but there is a thorny problem I can’t get around. BrowserStack support has not been able to help. Maybe it doesn’t happen to others. It is thus:
On iPad environments only, whether in Chrome or Safari, when I use OpenQA.Selenium.Interactions.Actions
functionality, a StaleElementReferenceExcepton is thrown. Every time. Reacquiring the element doesn’t work. Nor does waiting any amount of time, nor checking if IsDisplayed. I’ve tried acquiring during a WebDriverWait with that exception ‘ignored’. This happens (in about 300 different tests, every time) when calling .Perform()
after Actions
methods such as:
- MoveToElement()
- ContextClick()
- DoubleClick()
- DragAndDrop()
Specifically, the exception is thrown when I call the .Perform()
method after building my Actions
object. Exception message is the standard:
OpenQA.Selenium.StaleElementReferenceException: ‘The element identified by “5003” is either not present or it has expired from the internal cache. Try to find it again; For documentation on this error etc.
StaleElementReferenceException is probably a red herring. This does not behave in anyway like what you’ve seen if you use Selenium. (Normally, you see this periodically no matter how quickly you manipulate your new reference. You see it much more if your element reference hangs out for seconds, or if it is being otherwise manipulated.) This is repeatable, consistent, and the standard fixes don’t work.
I’m using:
- Selenium 4.17.0
- Selenium Grid through BrowserStack to their iPad Devices (apparently using Appium)
- C# Framework 4.8
Anyone have the work-around or configuration fix to get past this?