我使用 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");
或
UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap;
但它们不起作用。
你知道如何用键盘输入一些东西吗?
编辑: (只是为了让你们知道如何让 UIAKeyboard 适合您)
UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap;
不起作用
UIATarget.localTarget().frontMostApp().keyboard().keys()["A"].tap();
作品
和
UIATarget.localTarget().frontMostApp().keyboard().typeString("这是一条消息");
作品
最佳答案
您发布的最后两个代码片段应该可以工作,但它们仅在键盘打开(在屏幕上可见)时才有效。另一种方法是访问文本字段(您想在其中输入您要输入的内容),然后调用函数 .setValue("Hello world")
或 .typeString (“ Hello World ”)
。这两个是textField对象的函数。希望这会有所帮助。
关于javascript - iPhone - UI 自动化 - 使用 UIAKeyboard 键入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10638782/