【问题标题】:IPhone UI Testing - How to access delete key on keyboardiPhone UI 测试 - 如何访问键盘上的删除键
【发布时间】:2018-06-15 16:27:25
【问题描述】:

我目前正在测试一个文本字段。我可以选择所有文本,但随后弹出键盘,我想按键盘上的删除键删除所有文本。我该怎么做?

我目前拥有的:

[_app.menuItems[@"Select All"] tap];

我想要什么:

[_app.menuItems[@"Select All"] tap];
[_app.keyboard[@"delete"] tap]; // How do I do this?

【问题讨论】:

    标签: objective-c iphone xcode-ui-testing


    【解决方案1】:
    let app = XCUIApplication()
    let textField = app.textFields["myTextField"]
    textField.tap()
    textField.typeText(XCUIKeyboardKey.delete.rawValue)
    

    【讨论】:

      【解决方案2】:

      您可以使用XCUIKeyboardKey.delete 发送删除按键。

      let app = XCUIApplication()
      let textField = app.textFields["myTextField"]
      textField.tap()
      textField.typeKey(XCUIKeyboardKey.delete, modifierFlags: [])
      

      【讨论】:

      • typeKey 没有方法调用 textfield
      • @Oletha 混淆是由于您提到的方法是仅 macOS 的方法,而问题是关于 iOS。 Apple 的文档提到 typeKey:modifierFlags: 方法仅在此页面上为 macOS developer.apple.com/documentation/xctest/… 并且您可以在 XCUIElement.h 的标头中看到 #if TARGET_OS_OSX 在支持此方法的方法附近。
      【解决方案3】:

      您可以使用 (swift) : yourTextField.typeText(XCUIKeyboardKeyDelete)

      在 Obj-c 中: const XCUIKeyboardKey XCUIKeyboardKeyDelete;

      看这里: https://developer.apple.com/documentation/xctest/xcuikeyboardkeydelete?language=objc

      【讨论】:

        猜你喜欢
        • 2016-03-30
        • 2020-01-27
        • 1970-01-01
        • 2016-03-10
        • 2013-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-16
        相关资源
        最近更新 更多