I am currently in the process of developing selenium tests for a web application. The challenge I am facing is that the application utilizes dynamically generated forms, resulting in a plethora of non-unique elements to navigate through (#ids are limited or at a high level). These forms can also change based on configuration settings (making nth-child unreliable as the order of elements may vary).
Within these forms, there are specific fields that possess unique class names. However, these fields are nested within non-unique elements. I am looking for a solution to locate these elements based on their distinctive values (which are not #ids), ensuring that Selenium can find them regardless of their position within the form. Currently, I am unsure how to achieve this.
To better illustrate the scenario:
<Some non-unqiue Div>
<child>
<child>
<unique value 1>
<Some non-unqiue Div>
<child>
<child>
<unique value 2>
<Some non-unqiue Div>
<child>
<child>
<unique value I WANT THIS ONE>
<Some non-unqiue Div>
<child>
<child>
<unique value 4>
As depicted above, the element I am interested in has a distinct value that I need to match. Using nth-child(3) to navigate to its parent elements is not viable given the fluidity of their order. In some cases, the desired element may be positioned as nth-child(2).
Therefore, a potential selector for the scenario could resemble the following:
Some.nth-child(3) > child > child > [unique*=\"I WANT THIS ONE\"]
However, if the top parent changes to nth-child(2) in a different scenario, this approach would no longer be effective.
Is there a CSS selector technique that I can utilize to consistently locate this element by its unique value, irrespective of its parents' varying positions within the list?
Thank you in advance!