Reputation: 4479
I use UIAutomation
to test my iPhone app.
My app has a UISearchBar
, after I made it focused,
this line of script shows that the app now has 2 UIAWindow
.
UIATarget.localTarget().frontMostApp().logElementTree();
The second UIAWindow
has UIAKeyboard
as a child.
Do you know how to get a reference of the second UIAWindow
, so I could get a reference to the UIAKeyboard
?
I've tried
UIATarget.localTarget().frontMostApp().mainwindow()[1].keyboard().key()["Q"].tap();
but it doesn't work.
EDIT 1:
I use this line to get reference of the Keyboard. It works.
UIATarget.localTarget().frontMostApp().windows()[1].logElementTree();
but when I tried to type something with the keyboard:
UIATarget.localTarget().frontMostApp().keyboard().typeString("Hello world");
or
UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap;
but they don't work.
Do you know how to type some thing with the keyboard?
EDIT: (just to let you guys know how to make the UIAKeyboard works for you)
UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap;
doesn't work
UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap();
works
and
UIATarget.localTarget().frontMostApp().keyboard().typeString("This is a message");
works
Upvotes: 2
Views: 4543
Reputation: 949
The last two code snippets that you have posted should work, but they only work if your keyboard is open(visible on screen). An alternate way of doing this is to access the textfield(where you want to type whatever you are trying to type) and then call the function .setValue("Hello world")
or .typeString("Hello world")
. These two are functions of the textField object. Hope this helps.
Upvotes: 2
Reputation: 33416
To type with the keyboard once it's on screen:
UIATarget.localTarget().frontMostApp().keyboard().typeString("This is a message");
Upvotes: 0