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:
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.
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