Reputation: 5
I have problem testing news up ... I need to getAttribute("name") from page in app so I could compare the title of the news. To locate this title I used:
String storyTitle = driver.findElementByXPath("//android.view.View[@index ='1']").getAttribute("name");
But there is a problem because above this title there is another element that has the same xpath and I get it's content instead of the content I want.
Here is UIAutomator View of those elements:
I need to take that title in content-desc from element so I could compare it with title on previous screen that I pulled out of the news, but I don't know how to skip the first element, and go to the second one, because they have all the options the same exepc content-desc, and I can't use that. Any help?
Upvotes: 0
Views: 5366
Reputation: 4536
Use the findElementsByXPath
and get the "name" attribute of required occurrence of the element, in your case its 2nd occurrence - get(1)
.
String storyTitle = driver.findElementsByXPath("//android.view.View[@index ='1']").get(1).getAttribute("name");
Upvotes: 2