You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Appium Android Python无法找到UiAutomator2驱动问题求助

问题:本地Appium服务器无法识别已安装的UiAutomator2驱动

已成功安装UiAutomator2驱动,但本地运行Appium服务器时仍提示找不到该驱动。相同的期望配置(desired capabilities)在云Appium平台可正常运行,怀疑和配置或环境有关。

错误栈信息

Traceback (most recent call last):
  File "c:\Users\me\Documents\dic\tempCodeRunnerFile.python", line 20, in <module>
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\appium\webdriver\webdriver.py", line 230, in __init__
    super().__init__(
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\appium\webdriver\webdriver.py", line 320, in start_session
    response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Users\me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a driver for automationName 'UiAutomator2' and platformName 'Android'. Have you installed a driver that supports those capabilities? Run 'appium driver list --installed' to see. (Lower-level error: Could not find installed driver to support given caps)
Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not find a driver for automationName 'UiAutomator2' and platformName 'Android'. Have you installed a driver that supports those capabilities? Run 'appium driver list --installed' to see. (Lower-level error: Could not find installed driver to support given caps)
    at getResponseForW3CError (C:\Users\me\AppData\Roaming\npm\node_modules\appium\node_modules\@appium\base-driver\lib\protocol\errors.js:1067:9)
    at asyncHandler (C:\Users\me\AppData\Roaming\npm\node_modules\appium\node_modules\@appium\base-driver\lib\protocol\protocol.js:485:57)

UiAutomator2安装确认

appium driver install uiautomator2
√ Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
i Driver uiautomator2@2.14.0 successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]

运行代码

from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.appium_service import AppiumService
import time
"""os.system("start /B start cmd.exe @cmd /k appium -a 127.0.0.1 -p 4723")"""
appium_service = AppiumService()
appium_service.start(args=['--base-path', '/wd/hub'])
desired_caps = {
    'automationName': 'UiAutomator2',
    'platformName': 'Android',
    'deviceName': 'Galaxy S20+ 5G',
    'app': 'E:/g.apk',
    'appPackage': 'com.google.android.gm',
    'appActivity': 'com.google.android.gm.ui.MailActivityGmail',
    'fullReset': 'true',
    'newCommandTimeout': '3600',
    }
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(100)

排查方向

  • 检查驱动可见性:手动执行appium driver list --installed,确认输出中确实包含uiautomator2@2.14.0;同时检查Python环境的Appium版本与全局npm安装的Appium版本是否一致,避免环境隔离导致驱动不可见。
  • 环境路径问题:确认当前终端的PATH包含npm全局安装目录(如C:\Users\me\AppData\Roaming\npm),确保Appium服务能找到驱动;若使用虚拟环境,需在虚拟环境内重新安装驱动或调整PATH指向正确路径。
  • 服务启动方式排查:尝试手动启动Appium服务(执行appium --base-path /wd/hub),再运行代码连接,排除AppiumService启动时的环境差异问题。
  • 修正Capabilities参数:部分参数类型错误,fullReset应设为布尔值True、newCommandTimeout应设为整数3600;也可改用UiAutomator2Options构建配置,更符合W3C规范:
    options = UiAutomator2Options()
    options.set_capability('deviceName', 'Galaxy S20+ 5G')
    options.set_capability('app', 'E:/g.apk')
    options.set_capability('appPackage', 'com.google.android.gm')
    options.set_capability('appActivity', 'com.google.android.gm.ui.MailActivityGmail')
    options.full_reset = True
    options.new_command_timeout = 3600
    driver = webdriver.Remote('http://localhost:4723/wd/hub', options=options)
    
  • 兼容性检查:确认Appium版本与UiAutomator2驱动版本兼容,可尝试更新Appium到最新稳定版,或调整驱动版本至匹配版本。

内容的提问来源于stack exchange,提问作者John Silver

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 16:56:59