When you have a locator resolve to 2 elements, it is possible to write the locator in an xpath form with an index number specified to reach a single one:
However, similar to your other post, it doesn’t seem this application is too well built for testability. I’d also suggest:
Talking to your developers if this is built internally to add unique IDs or names to the elements you need to automate.
Consider a different software if this is built externally & off the shelf.
Also, please look at the surrounding, parent elements. I.e. you may find a uniquely identifiable panel which contains the button & that you could use something like:
//div[@id=‘uniqueIdHere’]/button
To any future member reading through this thread, just some extra advice here:
Please consider that sites can be multi-lingual & it’s best to check if your app has scope for this. Text-based recognition might likely not be the best option.
Also to check for whitespace & casing, the same with any other text comparison.
Locators using ID/name are fastest, then CSS locators, then finally XPath locators