Appium Appium zoom 方法使用无法生效

shuqing2017 · 2018年05月16日 · 最后由 shuqing2017 回复于 2018年07月12日 · 1053 次阅读

代码调用如下:

baidu_map=driver.find_element_by_id('com.baidu.BaiduMap:id/f6')
driver.zoom(baidu_map)

方法定义:

def zoom(self, element=None, percent=200, steps=50):
       """Zooms in on an element a certain amount

       :Args:
        - element - the element to zoom
        - percent - (optional) amount to zoom. Defaults to 200%
        - steps - (optional) number of steps in the zoom action

       :Usage:
           driver.zoom(element)
       """
       if element:
           element = element.id

       opts = {
           'element': element,
           'percent': percent,
           'steps': steps,
       }
       self.execute_script('mobile: pinchOpen', opts)
       return self

运行结果:

C:\Python35\python.exe D:/Appium/appium_action/muti_action.py
Traceback (most recent call last):
  File "D:/Appium/appium_action/muti_action.py", line 32, in <module>
    driver.zoom(baidu_map)
  File "C:\Python35\lib\site-packages\appium\webdriver\webdriver.py", line 354, in zoom
    self.execute_script('mobile: pinchOpen', opts)
  File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 627, in execute_script
    'args': converted_args})['value']
  File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Python35\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
    raise wde
  File "C:\Python35\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
    super(MobileErrorHandler, self).check_response(response)
  File "C:\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unknown mobile command "pinchOpen". Only shell commands are supported.


Process finished with exit code 1

经过谷歌+百度也没找到相关解决方案,查看了一下appium官方论坛也有人反馈这个缩放操作不生效:How To Zoomin And Zoom Out Using Appium

共收到 4 条回复 时间 点赞

补充一下测试环境:

测试环境

  • 夜神模拟器 Android 5.1.1
  • 百度地图Android app V10.6.5
  • Win 10 64bit
  • Appium 1.7.2

目前使用了一种替代方案实现了缩放,结合 MultiAction和TouchAction。

滑动原理图解

x = driver.get_window_size()['width']
y = driver.get_window_size()['height']



# 放大
def zoom():
    action1 = TouchAction(driver)
    action2 = TouchAction(driver)
    zoom_action = MultiAction(driver)

    action1.press(x=x*0.4, y=y*0.4).move_to(x=x*0.1, y=y*0.1).wait(500).release()
    action2.press(x=x*0.6, y=y*0.6).move_to(x=x*0.8, y=y*0.8).wait(500).release()

    print('start zoom...')
    zoom_action.add(action1, action2)
    zoom_action.perform()



# 缩小
def pinch():
    action1=TouchAction(driver)
    action2=TouchAction(driver)
    pinch_action=MultiAction(driver)

    action1.press(x=x*0.1, y=y*0.1).move_to(x=x*0.4, y=y*0.4).wait(500).release()
    action2.press(x=x*0.8, y=y*0.8).move_to(x=x*0.6, y=y*0.6).wait(500).release()

    print("start pinch...")
    pinch_action.add(action1, action2)
    pinch_action.perform()

请问楼主有相关文章吗?有的话请贴下关于原理图讲解的文章,想学习下

alex.pan TouchAction 手势操作无效 中提及了此贴 07月06日 10:30
shuqing2017 关闭了讨论 07月12日 16:33
shuqing2017 重新开启了讨论 07月12日 16:34
shuqing2017 关闭了讨论 07月12日 16:34
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册