This isn't absolutely necessary but it would make the code a lot shorter and presumably quicker. I would like to perform, using Selenium, the same actions on web elements elements that normally belong to the same class but if one of the elements is clicked, its class is dynamically changed to designate that it's "the active" element. I basically can only locate these elements by class name (XPATH). Is there a way to store elements that belong to different classes to the same variable to then perform manipulations on that variable?
If using XPath is the only option, you could take advantage of using logical operators in your selectors for your elements.
For example the following XPath:
//div[starts-with(@class, 'myclass')]|//div[starts-with(@class, 'myclass active')]
The above XPath says 'find all div tags which have a class which starts with 'myclass' OR all div tags which start with 'myclass active'.
Other XPath expressions like contains can be used to match text in any attribute on an element/collection of elements. Be careful when choosing the selector though to ensure that only the elements you want selected are selected .
Is there a way to contain web elements with different attributes in the same variable?