2

In this activity, I have 5 Text Views with same resource-id.

How can I select the first one with Java client Appium automation?

Is there any way to use resource-id and index combination.

I expect a non xpath strategy if available to select that.

UI Automator view

2 Answers2

2
  1. Select the Linear layout 1st.
  2. Then using <iList> iWebElement get all the elemants which have id name as Normal_view
  3. After that you will be getting a list of items of Text Views.
  4. Then access what ever the element you want using its index number.

below is a sample ,but in c#

 IList<IWebElement> sidemenuList = elm2.Modules.FindElements(By.TagName("li"));
            Thread.Sleep(3000);
            sidemenuList[4].Click();
ChathuD
  • 2,149
  • 22
  • 46
0

It depends what you are looking for, will you need to use all 5 textViews in your tests or will you only need the 3rd and never use others?

For the former create a list of webElements, then iterate through the list depending on which element you need at the moment. The syntax is pretty easy:

List<WebElement> elementsList = driver.findElements("your locator strategy")
elementsList.get(2).click; //this will click on the highlighted element from your screenshot

For the latter: 1. use either an xpath or UiAutomator locator (both have options to get to a specific element) 2. use page factory and @FindBys annotation to get a chained locator. 3. if the element you're looking for has a unique id - then you can locate it with id, else - don't. If you absolutely want to use id locators, then ask your developers to add unique ids to all elements that you need

SergioLeone
  • 121
  • 5