TestProject Forum
Powered by leading experts in the test automation community

IOS Same Element Names in Array Help

Hi Everyone,

I’m trying to select one of ten +/- icon that share the same Element Name. When I click the + icon, it always increases the first one. Is there any way to tell it to select the 3rd or 5th one? I tried adding a [5] next to the element location (as i’ve noticed that the button itself is listed this way as [5]). But this didn’t work.

This only happens on IOS, not Android. I’ve also tried recording but I guess the recorder is just trying to gather the element info/action.

I don’t have any selenium experience, i’ve had other experience with programming languages so I could read/understand what is happening… Any suggestions would be great!

Note: I’ve read that using a Safari browser and connecting the iPhone can reveal the elements also, would this be a good idea - could which element in the Array to select that Test Project isn’t picking up?

Thanks!

Hello @Lee
When you list the xpath of the element , surround it with parenthesis and then the brackets with the array notation.

For example (//*[contains(text(), ‘Test’)])[3], this will return the 4th item which is returned with that xpath.
Since this is array-like syntax it starts from 0.

Hi @ran.tzur, when I click Edit Element (within the step), the element type is a XCUIElementTypeCell, selector location AccessibilityID, and in the box below it just has “PlusButton_Modifier”. There is no path. When I use the find button on the step for the element, it picks up all the plus buttons.

The recorder captures the element xpath, you can find the element in the step that is created and edit the xpath of the element there:


You can then add the array notation to select only the plus button you want.

Hi! Thankyou so much for your response, it worked! You really helped me out here, really appreciate it!