Getting pretty desperate so I thought I'd reach out and see if others had ideas. The application that I'm automating has different forms and each of them open in different tabs within the application (they are not opening in browser tabs,). Many of the elements on the form are shared by the other forms. If I try to interact with an input field or a search button shared on another tab that I had opened in a previous step (even if I'm not focused on the previous form) then I get that the element cannot be interacted with. I'm unable to close the tabs there is no unique identifier for the close buttons on them. I tried to identify the close buttons by the class and use a loop to iterate and close them but that did not seem to work. I know this probably sounds confusing and wild.
Struggling to find solution for clicking element that is duplicated on different tabs of my application
Define list of web elements and assign all elements with the same identifier to that. Then use the index to reach the exact element. i.e :
@FindBy(id = "testID") List<WebElement> testList;
List<WebElement> testList = driver.findElemets(By.id("testID"));
and then use
i is the index of the element you want to reach out. Note that indexes start with
Of course the locator strategy I used is just a sample and you can use your own.
The key to this scenario is to understand xpath or html path for elements in the html document (or webpage) that is display how it is being constructed. There should be some form of grouping done by the application generator. If this has been identified next thing is to construct the FindBy annotation around that.
data-testidattribute for the controls in a section.