【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 的写法。欢迎继续提问!

相关推荐
BullSmall6 天前
自动化测试开发规范
selenium·测试工具·appium·自动化
BatyTao7 天前
Appium-Inspector下载安装全攻略
appium
阿蔹7 天前
UI测试自动化-Web-Python-Appium
前端·python·ui·appium·自动化
BatyTao13 天前
无线真机自动化测试全攻略-appium+phthon
appium
010不二17 天前
基于Appium爬虫文本导出可话个人动态(环境准备篇)
爬虫·python·appium
010不二17 天前
基于Appium爬虫文本导出可话个人动态
数据库·爬虫·python·appium
may_一一20 天前
appium安装(windows)
windows·appium
傻啦嘿哟25 天前
Appium实现Android应用数据爬取:从环境搭建到实战优化
android·appium
中冕—霍格沃兹软件开发测试1 个月前
边界值分析:功能测试中的精度利器
人工智能·功能测试·科技·测试工具·appium·bug
BatyTao1 个月前
vivo真机adb 命令获取手机当前窗口信息
adb·appium