2017-04-09 1 views
1

私は、テキストビューから前の値を削除しようとしていますが、私はカーソルがXC UIテスト中にテキストビューでテキストを削除しますか?

extension XCUIElement { 
    /** 
    Removes any current text in the field before typing in the new value 
    - Parameter text: the text to enter into the field 
    */ 
    func clearAndEnterText(text: String) -> Void { 
     guard let stringValue = self.value as? String else { 
      XCTFail("Tried to clear and enter text into a non string value") 
      return 
     } 

     self.tap() 

     let deleteString = stringValue.characters.map { _ in XCUIKeyboardKeyDelete }.joinWithSeparator("") 

     self.typeText(deleteString) 
     self.typeText(text) 
    } 
} 

ソース使用していたテキストview.Iの先頭に常にあるので、することができません:あなたはhttps://stackoverflow.com/a/32894080/2563133

+0

テキストフィールドにクリアボタンはありますか? (右の小さな灰色のxボタン) – Oletha

答えて

0

をあなたがテキストファイルをダブルタップし、キーボードから削除ボタンをタップすると簡単です。次のコードは動作するはずです:あなたがキーボードに依存したくないとあなたがクリップボードを利用していない場合

yourTextFieldElement.doubleTap() 
app.keys["delete"].tap() 
+0

ありがとう!私はちょうどこの行をmenuItems ["Select All"]の間に追加する必要がありました。tap() – rgkobashi

1

は、あなたがそれをカットすることができます

extension XCUIApplication { 
    func clearTextOnElement(_ element: XCUIElement) { 
     element.doubleTap() 
     menuItems["Select All"].tap() 
     menuItems["Cut"].tap() 
    } 
} 

Mr.ConstantChange answerに基づいています。

関連する問題