How to perform search on iOS device with XCUITest

I am working on automation testing on real iOS devices with Appium driver and XCUITest automator.
What I want my test to do is to enter text in a search bar and then to press search button.
However, I can not find a solution how to execute the searching action.
What I use for Android is await driver.execute(‘mobile: performEditorAction’, {action: ‘search’});, but I can not find similar action for iOS.
Could you please advise what would be the appropriate action for iOS?
Thank you in advance!

Thanks for the link. Definitely will use it for other questions, but for the current one I do not see any information.

AFAIK there is no direct alternative in iOS. I would try to locate the corresponding button on the on-screen keyboard and tap it

You mean last button on keyboard which changes on iOS depending on behavior: Next, Done, Go, Search and so on?

Yeah, this one. Maybe I could try with commands, which are for “Enter” button, like this one: driver.getKeyboard().pressKey(Keys.ENTER) . However, I tried this …getKeyboard() function, but it was not recognized in my project environment. It is strange how XCUITest does not support such common activities Search, Enter…etc.

Yeah, I will try this one, nevertheless it seems foolish approach, because as I said before, searching is a often used function, which obviously is not supported. :expressionless:

In the end, I will use the approach await $(’…’).setvalue(“some text” + “\n”). This will enter the “some text” in the search field with locator(selector) $(’…’) and the ‘\n’ will be executed as “Enter”. Another option to separate entering the text in the field and ‘pressing’ Enter is using these 2 function one after another:

  1. await $(’…’).setValue(“some text”);
  2. await $(’…’).addValue(’\n’);

finds last key on open keyboard for iOS

iOSClassChain = "**/XCUIElementTypeKeyboard[1]/**/XCUIElementTypeButton[-1]"
1 Like

Definitely will try this. Thanks!