问题描述
“ typeText”方法适用于'TextField'元素,但不适用于Xcode UI测试中的'TextEditor'元素。尝试了“连接硬件键盘”选项(启用/禁用),但未成功。有解决方法吗?
无法合成事件:元素或任何子代都没有键盘焦点。事件分发快照:TextView,标识符:'content'
let nameTextField = app.textFields["name"]
nameTextField.tap()
nameTextField.typeText("Test Name") // Working
let contentTextEditor = app.textViews["content"]
contentTextEditor.tap() // It successfully makes the cursor focus on the TextEditor element
contentTextEditor.typeText("Test Content") // Here is the error
解决方法
也许您可以尝试粘贴?
let contentTextEditor = app.textViews["content"]
UIPasteboard.generalPasteboard().string = "Test Content"
contentTextEditor.doubleTap()
app.menuItems.elementBoundByIndex(0).tap() // This is the ugly,but correct way to hit the paste button
XCTAssertEqual(contentTextEditor.value as? String,"Test Content")