# How can i make a long click action with a duration parameter on Android?

**URL:** <https://discuss.appium.io/t/how-can-i-make-a-long-click-action-with-a-duration-parameter-on-android/190>\
**Category:** Support\
**Created:** [September 7, 2014, 7:44am UTC](https://discuss.appium.io/t/how-can-i-make-a-long-click-action-with-a-duration-parameter-on-android/190 "2014-09-07T07:44:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@Alex](https://discuss.appium.io/u/Alex)\
**Post date:** [September 7, 2014, 7:44am UTC](https://discuss.appium.io/t/how-can-i-make-a-long-click-action-with-a-duration-parameter-on-android/190/1 "2014-09-07T07:44:00Z")

</div>

**First, what i will long\_click is not hard key, it is a button or icon on the screen.**

And i know how to do a normal long\_click without duration parameter, the default duration is 1 second.  
But i checked “appium.webdriver.common.touch\_action.TouchAction.long\_press(self, el=None, x=None, y=None, duration=1000)”, it is designed like this, see the code:

def long\_press(self, el=None, x=None, y=None, _ **duration=1000** _):

```
    self._add_action('longPress', self._get_opts(el, x, y))

    return self

```

Look, the parameter “duration=1000”, it is not be used in the function.  
And i did experiment, whatever duration you passed in, the long\_press action had no change.

So, brothers, how do you do 5 seconds long\_click? Please help me.

---

<div class="post-metadata">

**Author:** ![Alex](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@Alex](https://discuss.appium.io/u/Alex)\
**Post date:** [September 8, 2014, 8:23am UTC](https://discuss.appium.io/t/how-can-i-make-a-long-click-action-with-a-duration-parameter-on-android/190/2 "2014-09-08T08:23:45Z")

</div>

Solved!  
It seems Appium Python client issue, we need to modify two functions in “appium.webdriver.common.touch\_action.TouchAction”

long\_press(self, el=None, x=None, y=None, duration=1000)  
and  
\_get\_opts(self, element, x, y)

Modify them like this:

```
def long_press(self, el=None, x=None, y=None, duration=1000):
    self._add_action('longPress', self._get_opts(el, x, y, duration))
    return self

def _get_opts(self, element, x, y, duration = None):
    opts = {}
    if element is not None:
        opts['element'] = element.id
    # it makes no sense to have x but no y, or vice versa.
    if x is None or y is None:
        x, y = None, None
    opts['x'] = x
    opts['y'] = y
    if duration is not None:
        opts['duration'] = duration
    return opts
```

---

<div class="post-metadata">

**Author:** ![jennifer](https://discuss.appium.io/letter_avatar_proxy/v4/letter/j/46a35a/32.png) [@jennifer](https://discuss.appium.io/u/jennifer)\
**Post date:** [April 21, 2016, 7:04pm UTC](https://discuss.appium.io/t/how-can-i-make-a-long-click-action-with-a-duration-parameter-on-android/190/3 "2016-04-21T19:04:50Z")

</div>

> [@Alex](#):
>
> self.\_add\_action

Which version are you using? I don’t have this method…
