Appium Python + Appium 1.2.2, 关于长按 duration 的问题

Alex · 2014年09月12日 · 最后由 莫小贝 回复于 2014年11月07日 · 1474 次阅读

这个长按是指长按 element,在其他语言的 client 上我不知道是否有个问题

现在已经 merged 了,可以更新下直接用:https://github.com/appium/python-client

说一下之前不好用的原因,主要是 duration 这个参数没有被使用
"appium.webdriver.common.touch_action.TouchAction"

修改成这样

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
共收到 3 条回复 时间 点赞

很到位,很仔细~

https://github.com/appium/python-client
tap

The tap method stands alone, being unable to be chained with other methods. If you need a tap-like action that starts a longer chain, use press.

It can take either an element with an optional x-y offset, or absolute x-y coordinates for the tap, and an optional count.

el = self.driver.find_element_by_accessibility_id('Animation')
action = TouchAction(self.driver)
action.tap(el).perform()
el = self.driver.find_element_by_accessibility_id('Bouncing Balls')
self.assertIsNotNone(el)

以上是在 github 上看到的 or absolute x-y coordinates for the tap, and an optional count 这句的意思应该是只用坐标也可以完成 tap 方法吧? 我想完成只用坐标比如(65,10)的点击事件不需要 element,怎么用了以后报错?
代码如下:
def test_someActions(self):
sleep(8)
buttons = self.driver.find_elements_by_class_name("android.widget.Button")
buttons[1].click()
action = TouchAction(self.driver)
action.tap(65,10).perform()
sleep(5)

#2 楼 @sophia_sun1191 解决了 无须用 TouchAction, 应该是直接用 self.driver.tap([(65,10),])

需要 登录 後方可回應,如果你還沒有帳號按這裡 注册