【问题标题】:iPhone - UI Automation - Type with UIAKeyboardiPhone - UI 自动化 - 使用 UIAKeyboard 键入
【发布时间】:2013-12-10 01:34:49
【问题描述】:

我使用 UIAutomation 来测试我的 iPhone 应用程序。
我的应用程序有一个UISearchBar,在我让它集中之后,
这行脚本显示应用现在有 2 个UIAWindow

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

第二个UIAWindowUIAKeyboard 作为一个孩子。

你知道如何获取第二个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("This is a message");
有效

【问题讨论】:

    标签: javascript iphone ios-ui-automation


    【解决方案1】:

    您发布的最后两个代码 sn-ps 应该可以工作,但它们仅在您的键盘打开时才有效(在屏幕上可见)。另一种方法是访问文本字段(您想在其中输入您要输入的任何内容),然后调用函数.setValue("Hello world").typeString("Hello world")。这两个是 textField 对象的函数。希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      在屏幕上使用键盘输入:

      UIATarget.localTarget().frontMostApp().keyboard().typeString("This is a message");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-17
        • 1970-01-01
        • 1970-01-01
        • 2011-06-14
        • 2012-07-21
        • 1970-01-01
        • 2020-09-13
        • 1970-01-01
        相关资源
        最近更新 更多