Adding custom attributes to webelements (id)

0
During development of websites I haven't seen any way to add custom attributes. Most notably the “id” attribute is missing. In testing it is important to have clear, static id's on important webelements. This way a test is much more robust to changes, as you can change everything about a webelement while leaving the id alone. Unfortunately I can't find any way to do this. Mendix does add this automatically for some elements, but this is in truth no better than any random attribute. As an example, I have a “Search field” button. It is simple enough to click on this button via text, the id “mxui_widget_ControlBarButton_0", title and more. The problem is that all of these can be subject to change. The id is the worst offender, as from a tester perspective it is supposed to be static and never change. But we can see that if there's more similar buttons on the page we'll get id="mxui_widget_ControlBarButton_1" until id="mxui_widget_ControlBarButton_n". That means if the order changes, the test would select a different button. With updates to the widgets or in a new version of Mendix this might also change. This makes tests unreliable, taking up valuable time and effort if something breaks on the test side because of this. The tests should only fail if the software has a problem, not if the test has a problem. That is why I would like to see the option to add a custom fixed attribute to any webelement you want. This can be either fixed, or via certain logic. This way you can aid any test automation efforts. Or did I overlook such a function in the documentation/forum?
asked
2 answers
1

One approach you could take would be to give the elements you are trying to target custom class names. You can then target these in your testing software. These can be set from the Appearance tab of the element, in the Class field. You may want to come up with a naming convention for these so they don’t conflict with classes you are using for styling.

Hope this helps.

answered
1

Hi Eric,

Did you get a chance to look at the documentation here: Test Mendix Apps Using Selenium IDE | Mendix Documentation

In addition to Roberts answer and since you mentioned you are using Selenium, you should be able to change the Target id into a class name (see section 5 of the documentation). Then at least you are not dependent on all the “fluff around it”.

answered