I think the solution to above is prototypes - I have dealt with these before, as that's how at my last job we implemented most of the portlet and other advanced functionality in the product - through the use of blank, generic blocks of DOM that we clone, manipulate and inject into the page DOM. These prototypes are IDed - thus can only appear once on the page. The key is to get the right prototype, clone it, change it as we needed it, and inject it into the DOM - thereby "creating on the fly" a new and unique DOM element.
Adapting this technique to testing: create a number of raw prototypes - these should be the SAME prototypes you're currently using in your code. To ensure you're using the same prototypes, you might want to actually have a build-time step to join a single-set of prototypes to both the app pages as well as tests (which implies that tests should ALWAYS run during build).
So, using these prototypes, you would create a set of DOM elements, which will be the END RESULT, as you have designed your DOM to be, of what will happen once these prototypes go through the code and be injected into the page's DOM.
Check out the following links: