Angularjs – Testing Angularjs with Selenium without element id

angularjsseleniumtesting

Our team is working on a web app with AngularJS. For testing, we use Jasmine for unit testing and angular-e2e testing. That works fine. However, our QA team approached us today that they tried to use selenium for testing the web app but facing problems as we are not defining IDs for most DOM elements. We have researched a bit on this but no luck. May someone suggest a good way to do selenium test without having us to explicitly add in all the ids just for the use of selenium? Thanks!

Update

We have some meetings and ended up inserting ids to elements for robustness in testing. Thanks everyone for answering 🙂

Best Answer

If you are using Selenium WebDriver there are many ways to find elements on a page. XPATH is probably one of the better approaches as far as flexibility goes (though it can get ugly quickly) but WebDriver also allows you to use Class Names, Tag Names, Name, Link Text and CSS.

Selenium WebDriver - Locate UI Elements