代码调用如下:

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


↙↙↙阅读原文可查看相关链接,并与作者交流