Next Click Keyboard Using UIAutomation

I have a search field in my application and I set the return key type for this field to UIReturnKeyNext . I am trying to write a UIAutomation test that clicks the Next button on the keyboard using the following line:

 UIATarget.localTarget().frontMostApp().mainWindow().keyboard().keys().firstWithName("next"); 

This call fails because a key with the name "next" was not found. I did a reset of all the elements in my application using:

 UIATarget.localTarget().frontMostApp().logElementTree(); 

This shows that there is a key on the keyboard named "next", but somehow my attempt to get it, as shown above, still fails. However, I can get other keys (for example, the key for the letter "u") using this method. Is there a known issue here, or am I doing something wrong?

I tried other options with no luck:

 UIATarget.localTarget().frontMostApp().mainWindow().keyboard().elements()["next"]; 

Here is the screen capture of elements in my UIAKeyboard:

return key dump

+6
source share
4 answers

The following works for me:

 UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons().firstWi‌​thPredicate("name contains[c] 'next'"); 
+1
source

I don't have an example for testing, but since the Next button is a UIAButton, not a UIAKey, you can try:

 UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons()["next"]; 

If it does not work, you can also try

 UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons()[4]; 
+2
source

If you just want to click on it and you know that there is a “next” on the keyboard, like a “Return Key” (defined in your bank), you can use this:

 app.keyboard().typeString("\n"); 
+2
source

For me, the keyboard does not fall under mainWindow () into the view hierarchy. It is at the same level as mainWindow () when you logElementTree () from the top level. So what do you want to do:

 UIATarget.localTarget().frontMostApp().keyboard().buttons()["next"]; 

This worked for me when I tried to press the "Search" button on the keyboard.

0
source

Source: https://habr.com/ru/post/905241/


All Articles