python运行appium后报错No Chromedriver found that can automate Chrome ‘xx.x.x‘

appium踩坑

问题

在使用逍遥模拟器时候,在Python脚本中启动并运行Appium并驱动Chromedriver来切换上下文操作webview时运行报错具体错误信息如下:selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome ‘39.0.0’. You could also try to enable automated chromedrivers download server feature. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details,报错解释:未找到可自动执行Chrome ‘39.0.0’ 版本的Chromedriver驱动,代码如下

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/7/7 13:21
# @Author  : JaySun
# @Site    :
# @File    : demo11_H5_page.py.py
# @Software: PyCharm

from appium.webdriver import Remote

# Appium 连接配置
caps = {
    "deviceName": "127.0.0.1:21503",
    "app": r"D:\Program Files\PycharmProjects\app_pytest_framework\app\lemon_app_webview_debug.apk",
    "appPackage": "com.lemon.lemonban",
    "appActivity": "com.lemon.lemonban.activity.WelcomeActivity",
    "chromedriverExecutable": r"D:\Program Files\PycharmProjects\app_pytest_framework\driver\chromedriver_39.exe", #此处为报错位置,执行对应版本的浏览器驱动
    "platformName": "Android",
    "noSign": "true",
    "noReset": "true",
    "resetKeyboard": "true",
    "unicodeKeyboard": "true",
    "connectHardwareKeyboard": "true",
    "ensureWeb-viewsHavePages": "true",
    "nativeWebScreenshot": "true",
    "skipDeviceInitialization": "true",
    "skipServerInstallation": "true",
    "platformVersion": "5.1.1",
    "newCommandTimeout": 240,
    "automationName": "UiAutomator2"
}

# 创建 Appium 驱动对象
driver = Remote(desired_capabilities=caps, command_executor='http://127.0.0.1:4723/wd/hub')
driver.implicitly_wait(10)

# 原生页面操作元素
# 使用 'xpath' 定位方式,点击 "视频教程" 元素
driver.find_element('xpath', '//*[@text="视频教程"]').click()

# 等待 "WEBVIEW" 活动出现,超时时间为 10 秒
driver.wait_activity("WEBVIEW", 10)

# 上下文切换到对应 WEBVIEW 页面
# 切换到最后一个上下文(WEBVIEW_com.lemon.lemonban)
driver.switch_to.context(driver.contexts[-1])

# 在 WEBVIEW 页面操作元素
# 使用 'xpath' 定位方式,点击登录协议勾选框
driver.find_element('xpath', '//p[@class="login-protocol"]/i[@class="login-check-icon"]').click()
# 使用 'xpath' 定位方式,点击"更多登录方式"元素
driver.find_element('xpath', '//p[contains(text(),"更多登录方式")]').click()

# 打印当前上下文
print(driver.current_context)  # 当前上下文名称
# 获取页面所有的上下文
# 包括原生页面和 WEBVIEW 页面
contexts = driver.contexts
# 输出结果:['NATIVE_APP', 'WEBVIEW_com.android.launcher', 'WEBVIEW_com.lemon.lemonban']
# 'NATIVE_APP':代表原生页面
# 'WEBVIEW_com.lemon.lemonban':代表 WEBVIEW 页面
print(contexts)
# 关闭浏览器驱动
driver.quit()

原因

首先我尝试着将所有appium-chromedriver存放驱动的位置都更新为映射关系为2.14版本对应39.0.0 chromedriver驱动,映射关系详见网页链接,后来运行代码后依然同样报错,就去appium官网搜索,找到了如下内容
在这里插入图片描述
我代码中这一部分还是按照原有的appium1.x编码进行编写,但是官方团队已经升级了appium2.x所以导致原有desired_caps位置的如下代码执行会报错

desired_caps = {
"chromedriverExecutable": r"path"
}

解决

将这一部分代码改为同官网命令一致即可解决报错问题

desired_caps = {
"appium:chromedriverExecutable": r"path"
}

通过参考这位博主的博文来进行demo的编写以及排查问题所在,在此进行感谢!

转载请注明出处,感谢观看,互相学习!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值