My advice would be to use ATS for functional testing.
For more info check https://docs.mendix.com/addons/ats-addon/
Finding the right way to WAIT in a test case is one of the hardest aspects of writing UI tests with selenium. This is emphasized by the fact that the Mendix runtime is essentially a black box.
With Mendix you can never be sure that the runtime is not busy processing some microflow that when finished will trigger a refresh on the page and invalidate your selectors.
The result is the dreaded stale element exception – https://stackoverflow.com/questions/12967541/how-to-avoid-staleelementreferenceexception-in-selenium
I have no definitive solution for you but do take a look at FluentWait – https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html
Retries also might help.
Long time ago I tried to use Selenium with Mendix but without good results. I had similar problems.
I have the same issue!