LoginSignup
0
3

More than 3 years have passed since last update.

iOSのWebViewのUITestで全選択する

Last updated at Posted at 2019-12-05

概要

iOSのXCUITestで、WKWebViewのTextFieldで「すべての選択」できない問題への対処です。

通常のapp.textFieldsでアクセスできる要素は情報がありますが、
app.webViews以下への対応方法が見つからなかったのでいろいろ試してみました。

普通のTextFiledをtap()したときと違って、webViewだとカーソル位置が中央にくるのもタチが悪い 😇

「すべて選択 -> 削除」の動作を実現しています。

環境

  • Xcode9以上
  • iOS13対応
  • WKWebView対応
// TextFieldをとってくる
let textField = app.webViews.textFields.element(boundBy: num)

textField().tap()
textField().twoFingerTap()
textField().tap()
app.menuItems["すべてを選択"].tap()
textField().typeText(XCUIKeyboardKey.delete.rawValue)

これでどうだろうか。。。

補足

  • プロジェクトの言語設定が日本語のときは、すべてを選択でOK
    Project設定 -> TARGETS -> Info -> Custom iOS target Properties -> Localization native development region -> Japan

  • 英語環境のときはSelect AllでOK

  • Simulatorの言語設定は関係ないはずです。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3