`eraseText` only erases text until the middle if the text is long enough
When I tapOn a textInput, the cursors sets in the middle. When I use eraseText, it stats to delete from that point, but if my text was longer that the middle, some letters are not deleted, so I have to tap again and delete it again.
I would like to be able to complete delete the text input with a single command, or to be able to move the cursor to the end.
Hey @danielferromeral, thanks for creating the issue. Could you provide some more information? For example:
- OS, OS version, physical/virtual device?
- Framework used to build the app (e.g. SwiftUI, UIKit, Flutter, Compose?)
- screen recording would be great as well
Hi @bartekpacia. I have tried in two different devices (both are virtual) and in two different views.
One of the devices was a Virtual iPhone 15 with iOS 17.5, and the views were made with Swift and UIKit. The other device was a Virtual Pixel 8 Pro, and the views are made with Kotlin and Java, but not sure at all, the developer is in PTO.
The flow I used is this:
- runFlow:
label: "Erase Text"
commands:
- tapOn:
id: "emailInput"
- inputText "[email protected]"
- tapOn:
id: "emailInput"
- eraseText
- tapOn:
id: "emailInput"
- eraseText
And this is the result: https://github.com/user-attachments/assets/d9ab49ff-39de-48b0-a375-8a32bbf20b01
Thanks a ton. If you could also drop an .apk, .app or some sample code in e.g. SwiftUI, that'd be great!
Hi, I cannot provide a sample code, sorry, not a mobile dev. But I guess you could use any input text, like the search bar in the settings for Android. In fact, I made this little script with the search bar of the setting app and is the same bahavoiur. Hope it helps.
appId: com.android.settings
---
- launchApp
- tapOn:
id: "com.android.settings:id/search_action_bar"
- inputText: "Lorem ipsum dolor sit amet"
# Here you would do other actions and the cursor would be no longer at the end of the text
- tapOn:
id: "com.google.android.settings.intelligence:id/open_search_view_edit_text"
- eraseText
- tapOn:
id: "com.google.android.settings.intelligence:id/open_search_view_edit_text"
- eraseText
- stopApp
Thanks @danielferromeral, I was able to reproduce the problem thanks to your code sample.
Run video
https://github.com/user-attachments/assets/86b8bb36-dc9a-49bf-ae15-15b22ae4dcc9
Running into the same problem with Maestro CLI v1.38.1 when executing tests on a physical Android device (OnePlus Nord, Android 12, connected to Windows 11 via USB). Also, this looks like it's a duplicate of #495.
eraseText still place cursor in the middle of text ( only 15 chars) and erase first half... had to make like this to work . any better solution please ?
- tapOn:
id: "stringid"
- eraseText
- tapOn:
id: "stringid"
- eraseText
- tapOn:
id: "stringid"
- eraseText
Here's a utility flow I wrote for one of my projects. It's a little slower (moreso when the text is short and 'Select All' isn't visible), but it's reliable:
appId: ${APP_ID}
jsEngine: graaljs
# Clear a given text field, avoiding flakiness in iOS (https://maestro.mobile.dev/api-reference/commands/erasetext)
# and avoiding issues of not erasing portions of long text already present
env:
FIELD_ID: ${FIELD_ID}
---
- runFlow:
when:
visible:
id: ${FIELD_ID}
commands:
- tapOn:
id: ${FIELD_ID}
- longPressOn:
id: ${FIELD_ID}
- runFlow:
label: Select All
# Sometimes you won't get Select All, but will get Cut, Paste, etc. That's fine - it's probably all selected anyway
when:
visible: 'Select All'
commands:
- tapOn: 'Select All'
- eraseText: 1
I'm going to close this as a duplicate of #495, but reference it there - there's some good content and conversation here.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue. Thank you for helping keep us our issue tracker clean!