Currently, I am conducting E2E tests on an application that lacks clear identification for the tags. I need to click on buttons nested deeply within the structure, some of which have the same name and properties as others.
The HTML code presents itself similarly to the following:
<div class='.ui .row'>
<div class='.ui .fluid'>
<div class='.content'>
<div>
<div class='.field'>
<button>Button</button>
</div>
</div>
</div>
<div class='.content'>
<div>
<div>Some other stuff</div>
<div class='.field'>
<button>Button</button>
</div>
</div>
</div>
</div>
</div>
Due to having two buttons with the same name, I cannot simply use browser.click('button*=Button')
. Instead, I am currently using this approach:
browser.click('div > div > div > div > div > button')
For the second button, a different selector is needed like this:
browser.click('div > div > div:nth-child(2) > div > div:nth-child(2) > button')
Although this method works, I have encountered several issues: - The code is not visually appealing and can be confusing for someone new to it - It is prone to breaking with even minor changes in the app's structure, unrelated to the buttons themselves
My query is whether there is a more efficient way to target these buttons under the given conditions.