0

I have a mobile ios app, which generates elements dynamically, i am struggling on clicking some checkboxes because they do not have an id or value like a common checkbox in web application, please look at the image below. (sorry i can't show all image, but app is in development)

enter image description here

Appium inspector gives me the xpath, but i do not like it because it changes depending on which elements are seen on the screen, since i have to scroll down the page, depending on the device, sometimes some checkboxes are displayed sometimes they are not, so the [4] element for example will change.

I want to know if there is a way to click the checkbox by concatenating the text adjacent to the checkbox, so that way it does not matter how many checkboxes are displayed on screen, it will always check by text.

enter image description here

so at the end i have an xpath something like:(//XCUIElementTypeButton[@name="checkbox unselected"])[and text='The hydraulic system was operational']

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Adrian Jimenez
  • 979
  • 9
  • 23
  • Is there no way to add an id programmatically? – arcadeblast77 Sep 05 '19 at 19:06
  • There are like a 1000 checkboxes in the app, i doubt the development team wants to add ids for all, and as i said, i think those elements are created dinamically by the app, maybe they are loaded and created as necessary in the app. – Adrian Jimenez Sep 05 '19 at 19:35
  • I see inconsistency in `` node, did you customized the html to post in this question or that's how it's showing in the application. If you look at the pattern first you have 2 checkbox related nodes and then you have 2 static text nodes. But the last checkbox node is followed by the static text rather it should be either at the top or each static text should have corresponding checkbox node. If you could confirm that, I would be able to provide a simple xpath. – supputuri Sep 06 '19 at 02:40
  • Rightly saide by @Su – atul parate Sep 06 '19 at 06:04
  • The code is like that, i took a screenshot from appium inspector session – Adrian Jimenez Sep 06 '19 at 13:58

1 Answers1

1

If you were sure that you had an structure where every checkbox is followed by a label/text, you could then look for that label, then look for the first preceding-sibling.

//XCUIElementTypeStaticText[@name="The hydraulic system was operational"]/preceding-sibling::XCUIEelementTypeButton[1]

However, this may not work seeing your structure. It seems like checkboxes appear in the same order as the labels, so you could then get the relative index of those labels, and then get checkbox by index. Something like:

//label/../checkbox[count(label/preceding-sibling::LabelType)+1]

//XCUIElementTypeStaticText[@name="The hydraulic system was operational"]/../XCUIEelementTypeButton[count(//XCUIElementTypeStaticText[@name="The hydraulic system was operational"]/preceding-sibling::XCUIElementTypeStaticText)+1]

Anyway, none of this solutions are the best. You should ask the developers to put proper attributes.

Alexis
  • 443
  • 4
  • 11