Select text from Menu Token field in Xcode UITests

the_kaseys Source

UITests - token field with dropdown menu

I saw a WWDC video about UITests that said if you double-click the blue token field in Xcode, it will become text and remove the menu (aka. the blue thing), but when I double-click the field, it just gets removed.



answered 1 week ago the4kman #1

The double-tap trick is, indeed, not working in Xcode 9. However, we can always use the power of Regex.

For this to work, either:

  • open the Find navigator on the left sidebar (the fourth icon from the left) and choose Replace from the first toggle on the top
  • navigate to Find/Find and Replace...

After that, choose the Regular Expression option by:

  • clicking on the menu and changing the searching method if you're using the Find navigator
  • or by opening the menu on the right side (to the right of the button with the text Aa) if you prefer to use the local Find and Replace dialog

The start of the token field is always indicated with /*@[email protected]*/, followed by the actual selected text. After that, there is a textual representation of all the possible options, finished with @[email protected]*/. Example:

/*@[email protected]*/.cells.buttons["Button Text"]/*[[".cells.buttons[\"Button Text\"]",".buttons[\"Button Text\"]"],[[[-1,1],[-1,0]]],[1]]@[email protected]*/

In our Regex, we should delete everything but the text that comes directly after /*@[email protected]*/ and before the options block. We can achieve this by capturing that snippet and replacing all of this mess with just that snippet.

For Replace, enter the following:

/\*@[email protected]\*/(.*.)/\*(.*.)@[email protected]\*/

...and for With, enter this:


Click on Replace if you only want to delete the token field from the nearest occurrence after your cursor or choose All if you want to remove them all.

screenshot of the Find and Replace... dialog

comments powered by Disqus