记录使用appium+夜神模拟器测试多设备时selenium和appium版本不兼容带来的问题

记录使用appium+夜神模拟器测试多设备时selenium和appium版本不兼容带来的问题

好不容易解决了selenium和appium的版本冲突问题(导致:AttributeError: 'NoneType' object has no attribute 'to_capabilities'异常发生)

第二天运行代码发现出现了连接Appium 服务器被拒绝

bash 复制代码
http://127.0.0.1:4723/wd/hub
Exception in thread Thread-2 (appim_desired_01):
Traceback (most recent call last):
  File "E:\anaconda3\Lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\anaconda3\Lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "E:\anaconda3\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

后来发现Appium 服务器没有启动成功

bash 复制代码
[ERROR] Unrecognized arguments: -bp 4724

在使用 start 命令启动 Appium 时,如果遇到"Unrecognized arguments: -bp 4724"错误,这可能是因为你使用的 Appium 版本不支持 -bp 参数。看来是解决selenium和appium版本冲突问题时降低了appium版本导致的

解决方法

  1. 对于 Appium,通常需要指定的参数为 --port 和 --base-path。如果你想设置基础路径,可以使用 --base-path 替代 -bp。因此,修改后的命令如下:
bash 复制代码
start /b appium -a 127.0.0.1 -p 4723 --base-path /wd/hub
  1. 在连接到 Appium 服务器时,所请求的会话缺少 automationName 参数的话会出现错误Error connecting to Appium server: Message: 'automationName' can't be blank。automationName 是 Appium 的一个重要配置项,用于指定使用的自动化引擎,比如:
  • UiAutomator2(适用于 Android)
  • XCUITest(适用于 iOS)
bash 复制代码
desired_caps = {
    'platformName': 'Android',
    'platformVersion': '5.1.1',  # 确保这个版本与你的设备匹配
    'deviceName': '127.0.0.1:62025',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings',  # 等待的活动
    'noReset': False,
    "automationName": "UiAutomator2"
}
  1. 设置参数后需要安装相应的驱动。 否则Appium 没有找到与 automationName 为 UiAutomator2 和 platformName 为 Android 的配置相匹配的驱动程序会出现错误Error connecting to Appium server: 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)v

  2. 解决步骤

    1)检查已安装的驱动:

    运行以下命令查看已安装的驱动程序:

bash 复制代码
appium driver list --installed

确保 appium-uiautomator2-driver 驱动程序已安装。如果没有,你需要安装它。

2)安装 UiAutomator2 驱动:

如果你没有安装 UiAutomator2 驱动,可以通过以下命令安装:

bash 复制代码
appium driver install uiautomator2

再次运行代码-成功


相关推荐
czhc11400756637 分钟前
Linux 76 rsync
linux·运维·python
悠悠小茉莉38 分钟前
Win11 安装 Visual Studio(保姆教程 - 更新至2025.07)
c++·ide·vscode·python·visualstudio·visual studio
m0_625686551 小时前
day53
python
Real_man1 小时前
告别 requirements.txt,拥抱 pyproject.toml和uv的现代Python工作流
python
站大爷IP2 小时前
Python文件操作的"保险箱":with语句深度实战指南
python
运器1232 小时前
【一起来学AI大模型】算法核心:数组/哈希表/树/排序/动态规划(LeetCode精练)
开发语言·人工智能·python·算法·ai·散列表·ai编程
巴里巴气4 小时前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
19895 小时前
【零基础学AI】第26讲:循环神经网络(RNN)与LSTM - 文本生成
人工智能·python·rnn·神经网络·机器学习·tensorflow·lstm
JavaEdge在掘金5 小时前
Redis 数据倾斜?别慌!从成因到解决方案,一文帮你搞定
python
ansurfen5 小时前
我的第一个AI项目:从零搭建RAG知识库的踩坑之旅
python·llm