【appium】6.appium遇到的问题

1.appium-python-client 修改版本1.5 为5.1.1,后执行python程序时,提示: raise TypeError( TypeError: missing 1 required keyword-only argument: 'options' (instance of driver `options.Options` class)

你遇到的错误:

复制代码
TypeError: missing 1 required keyword-only argument: 'options' 
(instance of driver `options.Options` class)

📌 错误原因分析

这是 Appium-Python-Client 版本升级带来的 API 不兼容问题

你从版本 1.5 升级到了 5.1.1,这是一个非常大的版本跳跃,其中 Appium 客户端库进行了重大更新(主要是与 Selenium 的整合和重构)。


🔍 旧版 vs 新版 WebDriver 初始化方式对比

✅ 旧版(Appium-Python-Client < 3.x)

复制代码
from appium import webdriver

desired_caps = {
    'platformName': 'Android',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.example.app',
    'appActivity': '.MainActivity'
}

driver = webdriver.Remote('http://localhost:4723', desired_caps)

这个写法在新版本中已经不被支持了!


✅ 新版(Appium-Python-Client ≥ 5.0)

现在要求使用 options 参数来代替直接传入 desired_caps,这与新版 Selenium 的风格一致。


✅ 正确修改方法(适用于 Appium-Python-Client 5.1.1)

你需要将原来的 desired_caps 放入一个 options 对象中。

✅ 修改后的代码如下:

复制代码
from appium import webdriver
from appium.options.android import UiAutomator2Options

# 设置 Desired Capabilities
desired_caps = {
    'platformName': 'Android',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.example.app',
    'appActivity': '.MainActivity',
    'automationName': 'UiAutomator2',
    'noReset': True
}

# 使用新的 Options 类封装
options = UiAutomator2Options().load_capabilities(desired_caps)

# 创建 WebDriver 实例
driver = webdriver.Remote(
    command_executor='http://localhost:4723',
    options=options
)

print("Driver started:", driver)

🧪 常见注意事项

注意事项 说明
UiAutomator2Options Android 测试时推荐使用这个类
options 是必须参数 新版要求必须使用 options 而不是 desired_caps
command_executor 就是你的 Appium Server 地址:http://localhost:4723

✅ 如何降级回旧版本?(可选)

如果你暂时不想改代码,可以考虑降级到旧版本:

复制代码
pip install Appium-Python-Client==1.5.0

但这只是临时方案,建议尽快迁移到新版 API。


✅ 总结

问题 解决方法
TypeError: missing keyword-only argument 'options' 使用 options 参数代替 desired_caps
Appium Python Client 5.1.1 兼容性问题 使用 UiAutomator2Options.load_capabilities() 包装 desired_caps
推荐做法 使用新版 API,适配未来更新

如果你愿意贴出你的完整代码片段,我可以帮你逐行修改成兼容 5.1.1 的写法。欢迎继续提问!

相关推荐
中冕—霍格沃兹软件开发测试2 天前
边界值分析:功能测试中的精度利器
人工智能·功能测试·科技·测试工具·appium·bug
BatyTao2 天前
vivo真机adb 命令获取手机当前窗口信息
adb·appium
中冕—霍格沃兹软件开发测试2 天前
探索性测试:思维驱动下的高效缺陷狩猎
人工智能·科技·开源·appium·bug
中冕—霍格沃兹软件开发测试3 天前
Git版本控制在测试项目管理中的应用
人工智能·git·科技·开源·appium·bug
中冕—霍格沃兹软件开发测试3 天前
用户体验测试:功能与界面并重
人工智能·科技·开源·appium·bug·ux
中冕—霍格沃兹软件开发测试4 天前
测试工具链的构建与团队协作:从工具集成到价值流动
人工智能·科技·测试工具·开源·appium·bug
仪***沿5 天前
基于粒子群算法的 33 节点配电网重构 MATLAB 程序探索
appium
测试人社区—84167 天前
Appium移动自动化测试:从入门到精通实战
人工智能·安全·appium·自动化·bug·postman
我会一直在的8 天前
Appium的基础API介绍
python·appium·自动化
聊天QQ:6882388615 天前
Comsol 探索增强型地热开采:一年温度变化的奇妙之旅
appium