Issue
I am trying to test an EditText
that already contains some text using Espresso
. The problem is that when I use typeText()
, the cursor is placed at an arbitrary position within the text. I tried performing click()
before using typeTextIntoFocusedView
but the cursor is sometimes placed at the beginning of the EditText
. I want to know is it possible to set the cursor at the end of the EditText
before typing text into it?
Solution
The only way I have found to do this is to get a reference to the EditText
itself and use EditText#setSelection()
. For example, to move the cursor to the end of the current text:
val activity = activityRule.activity
val tv = activity.findViewById<EditText>(R.id.edittext)
activity.runOnUiThread { tv.setSelection(tv.text.length) }
Answered By - Clyde
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.