Javascript iPhone-UI自动化-使用UIAKeyboard键入
我使用Javascript iPhone-UI自动化-使用UIAKeyboard键入,javascript,iphone,ios-ui-automation,Javascript,Iphone,Ios Ui Automation,我使用UIAutomation测试我的iPhone应用程序。 我的应用程序有一个UISearchBar,在我使其成为焦点后, 这行脚本显示应用程序现在有2个UIAWindow UIATarget.localTarget().frontMostApp().logElementTree(); 第二个UIAWindow作为孩子拥有UIAKeyboard 您知道如何获取第二个UIAWindow的引用,以便我可以获取对UIAKeyboard的引用吗 我试过了 UIATarget.localTarget
UIAutomation
测试我的iPhone应用程序。我的应用程序有一个
UISearchBar
,在我使其成为焦点后,这行脚本显示应用程序现在有2个
UIAWindow
UIATarget.localTarget().frontMostApp().logElementTree();
第二个UIAWindow
作为孩子拥有UIAKeyboard
您知道如何获取第二个UIAWindow
的引用,以便我可以获取对UIAKeyboard
的引用吗
我试过了
UIATarget.localTarget().frontMostApp().mainwindow()[1].keyboard().key()["Q"].tap();
但它不起作用
编辑1:我用这一行来获取键盘的参考。它起作用了
UIATarget.localTarget().frontMostApp().windows()[1].logElementTree();
但是当我试着用键盘输入一些东西时:
UIATarget.localTarget().frontMostApp().keyboard().typeString("Hello world");
或
但它们不起作用
你知道如何用键盘打字吗?
编辑: (只是想让你们知道如何让UIAKeyboard适合你们)
UIATarget.localTarget().frontMostApp().keyboard().keys()[“A”]点击
不起作用
UIATarget.localTarget().frontMostApp().keyboard().keys()[“A”].tap()
有效 和
UIATarget.localTarget().frontMostApp().keyboard().typeString(“这是一条消息”)
有效您发布的最后两个代码片段应该有效,但它们只有在键盘打开(在屏幕上可见)时才有效。另一种方法是访问textfield(您想在其中键入任何您想键入的内容),然后调用函数
.setValue(“Hello world”)
或.typeString(“Hello world”)
。这两个是textField对象的函数。希望这对您有所帮助。要在键盘出现在屏幕上后使用键盘进行键入:
UIATarget.localTarget().frontMostApp().keyboard().typeString("This is a message");
UIATarget.localTarget().frontMostApp().keyboard().typeString("This is a message");