How to use copy paste option using long tap action in android


#1

I an automating android native app
and for eg.in login page I want to copy email id using long tap and select copy option from context
and want to paste into password field ?

How to automate this scenario using appium ?

1.Long tap gesture
2.Select all the text in that textbox field
3.Use context copy menu
4.Use long tap on password field
5.Try to paste again using long tap and context paste option


#2

Why do you want copy it in this way?
You can just getText of element and set text into password field.


#3

Hi @Degard , Actually my requirement for application says that You can not paste anything in password field on login page, So I want to know
1.Whether I can copy password field text or not ? gettext doesn’t work in password field
2.Whether I can paste any text copied from any other field into password field or not ? since gettext will always copy the text to variable and sendkeys will paste that into my password field but requirement says long tap copy/paste option should be disabled for password field so I want to automate this requirement


#4

In this case just check if element enabled or something like this (look at attributes of element).


#5

You can paste (setValue or sednKeys) text to webElement only if this element enabled and editable.


#6

If you long press on a text field, the Paste menu appears and that cannot be identified.
There is workaround for that, it may sound silly but works fine. Below are the steps

  1. type a dummy text in the text field. (Note.: it should be long enough to cover more than half of the text field width)
  2. Find the center of the text field and use long press with location coordinates
  3. Now the action bar appears with Cut / copy / paste options which are identifiable
  4. clicl on the Paste in the Action Bar

Jerald


#7

Hi @jervinjn

Am able to see the COPY option. But am not able to to tap on “COPY” as its not visible in the inspector.

How did you mange to click on PASTE option.

Thanks,


#8

I am challenging the same issue. I even tried TouchAction with pressing particular coordinates, but it doesn’t work correctly.

new TouchAction(getDriver())
        .longPress(longPressOptions)
        .release()
        .press(PointOption.point(293, 244))
        .waitAction(waitOptions(ofMillis(1000)))
        .perform();

#9

One can also interact with clipboard directly since Appium 1.8: https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/clipboard/HasClipboard.java