I see two possible intepretations of your question here. The first is "How can I improve the speed of how elements are found on a page?". Another is "How can I improve execution speed of my suite of tests?".
The first question has some answers already. You've found that
id doesn't provide much speedup, so you're almost at the end of the road there.
The second question has more answers. Remember that if you're using WebDriver for end-to-end test automation, there's many, many things that affect your tests, such as
- Browser rendering of HTML
- Browser JS compilation and execution
- Internet connection speed
- CSS Styling
- DOM Generation and updating
- Screen resolution
- Application load time
- Browser navigation
- HTML structure
- Server-side application logic
- Client-side application logic
These may all affect how stable your tests are, and in turn how well they run.
To get better run-time performance, I'd suggest the following:
- Make sure your network connections/Internet connections are reliable and as fast as possible. Latency causes your apps to run more slowly which in turn causes tests to run more slowly.
- Use physical or virtual machines with good hardware specs. Running on low-powered machines (in terms of RAM or CPU) may cause flakiness in your web app which in turn causes flaky tests.
- Run your tests in parallel as much as possible. Divide large suites into smaller suites that can be run independently at the same time.
- Avoid writing low-value tests. End-to-end tests are inherently long-running tests, and so tests that don't contribute much to understanding your application waste run-time.
- Write deterministic tests. Tests that don't require a lot of overhead in terms of setup and teardown run quicker and more reliably.
In my experience these are effective ways to get your test run-time down.