1

When doing my element query in my UITests, to take screenshots of the different segmented control value, an error is thrown when translation comes into play because I use .buttons["name"], and the name is in English and is not being translated as expected. It has been translated from the storyboard. So I would like to find a simpler solution.

Can I have the .selectedSegmentIndex instead of the button name that has translation error in UITest, or is there another way to fix this issue?

XCUIApplication().scrollViews
  .children(matching: .other)
  .element
  .children(matching: .other)
  .element(boundBy: 0)
  .children(matching: .other)
  .otherElements
  .segmentedControls["MySegmentedControl"]
  .buttons["name"] // How to add this value to be .selectedSegmentIndex = 1?
  .tap()
Roland Lariotte
  • 2,606
  • 1
  • 16
  • 40
  • 1
    Did you try `app.segmentedControls.buttons.element(boundBy: 1)` ? – Omer Faruk Ozturk Jul 21 '20 at 08:09
  • 1
    It doesn't work, I get this error: Failed to get matching snapshot: No matches found for Descendants matching type SegmentedControl from input – Roland Lariotte Jul 21 '20 at 08:20
  • 1
    I mean `.segmentedControls["MySegmentedControl"].buttons.element(boundBy: 1)`, instead of `segmentedControls["MySegmentedControl"].buttons["name"]`. you tried so, right? – Omer Faruk Ozturk Jul 21 '20 at 08:26
  • I tried this solution but triggers the same error. – Roland Lariotte Jul 21 '20 at 09:18
  • btw, did you access to segment control before with the code you share? You need to launch first, then access through the `app`. not like `XCUIApplication().segmentedControls ` – Omer Faruk Ozturk Jul 21 '20 at 10:21
  • All of this is done in the setup(), I just shorten the code to make it readable on StackOverflow. The flow is correct until I hit the code I shared in another language than English. – Roland Lariotte Jul 21 '20 at 11:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218277/discussion-between-omerfarukozturk-and-roland-lariotte). – Omer Faruk Ozturk Jul 21 '20 at 11:22

1 Answers1

2

You can access an element at specified index using element(boundBy:)

For your case;

app.scrollViews
.segmentedControls
.buttons
.element(boundBy: 1)
.tap()
Omer Faruk Ozturk
  • 1,722
  • 13
  • 25