当前位置: 首页 > news >正文

python中appium 的NoSuchElementException错误 原因以及解决办法

错误收集

D:\Program\Util\python.exe "D:/Program/myUtil/PyCharm 2024.3.5/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" --target demo.py::TestAppium 
Testing started at 15:57 ...
Launching pytest with arguments demo.py::TestAppium --no-header --no-summary -q in C:\Users\Administrator\PycharmProjects\pyAppium

============================= test session starts =============================
collecting ... collected 1 item

demo.py::TestAppium::test_study 

======================== 1 failed, 3 warnings in 6.18s ========================
FAILED                                   [100%]
demo.py:15 (TestAppium.test_study)
self = <demo.TestAppium object at 0x00000298250C8B90>

    def test_study(self):
>       ele = self.app_do.find_element(by=AppiumBy.ID,value="com.microvirt.launcher2:id/tv_hint_name")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

demo.py:17: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
D:\Program\Util\Lib\site-packages\selenium\webdriver\remote\webdriver.py:922: in find_element
return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
D:\Program\Util\Lib\site-packages\selenium\webdriver\remote\webdriver.py:454: in execute
self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <appium.webdriver.errorhandler.MobileErrorHandler object at 0x00000298252001A0>
response = {'status': 404, 'value': '{"value":{"error":"no such element","message":"An element could not be located on the page u...ode_modules\\\\appium\\\\node_modules\\\\@appium\\\\base-driver\\\\lib\\\\basedriver\\\\commands\\\\find.ts:75:12)"}}'}

    def check_response(self, response: Dict[str, Any]) -> None:
"""
https://www.w3.org/TR/webdriver/#errors
"""
payload = response.get('value', '')
if isinstance(payload, dict):
payload_dict = payload
else:
try:
payload_dict = json.loads(payload)
except (json.JSONDecodeError, TypeError):
return
if not isinstance(payload_dict, dict):
return
value = payload_dict.get('value')
if not isinstance(value, dict):
return
error = value.get('error')
if not error:
return

message = value.get('message', error)
stacktrace = value.get('stacktrace', '')
# In theory, we should also be checking HTTP status codes.
# Java client, for example, prints a warning if the actual `error`
# value does not match to the response's HTTP status code.
exception_class: Type[sel_exceptions.WebDriverException] = ERROR_TO_EXC_MAPPING.get(
error, sel_exceptions.WebDriverException
)
if exception_class is sel_exceptions.WebDriverException and message:
if message == 'No such context found.':
exception_class = appium_exceptions.NoSuchContextException
elif message == 'That command could not be executed in the current context.':
exception_class = appium_exceptions.InvalidSwitchToTargetException

if exception_class is sel_exceptions.UnexpectedAlertPresentException:
raise sel_exceptions.UnexpectedAlertPresentException(
msg=message,
stacktrace=format_stacktrace(stacktrace),
alert_text=value.get('data'),
)
>       raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace))
E       selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#nosuchelementexception
E       Stacktrace:
E       NoSuchElementError: An element could not be located on the page using the given search parameters.
E           at AndroidUiautomator2Driver.findElOrEls (C:\Users\Administrator\.appium\node_modules\appium-uiautomator2-driver\node_modules\appium-android-driver\lib\commands\find.ts:86:11)
E           at runMicrotasks (<anonymous>)
E           at processTicksAndRejections (node:internal/process/task_queues:96:5)
E           at AndroidUiautomator2Driver.findElOrElsWithProcessing (D:\Program\Util\nvm\nvm\v16.20.2\node_modules\appium\node_modules\@appium\base-driver\lib\basedriver\commands\find.ts:60:12)
E           at AndroidUiautomator2Driver.findElement (D:\Program\Util\nvm\nvm\v16.20.2\node_modules\appium\node_modules\@appium\base-driver\lib\basedriver\commands\find.ts:75:12)

D:\Program\Util\Lib\site-packages\appium\webdriver\errorhandler.py:125: NoSuchElementException

Process finished with exit code 1

错误分析

NoSuchElementException

使用appium定位的时候,没有定位到该元素。

解决办法

使用其他的定位方式

  • 使用ID定位
  • 检查是不是定位方式出错了
  • 使用class定位
  • 使用XPath定位
  • 或者使用名字定位
  • Css选择器定位

运行结果

使用其他中方式定位可以解决。

http://www.dtcms.com/a/310412.html

相关文章:

  • C++基础语法
  • Redis实战(5)-- 高级数据结构 HyperLogLog
  • 调整Idea缓存目录,释放C盘空间
  • UniApp与WebView双向通信机制及生产级实现方案全解析
  • 振动波形转音频播放并做声纹聚类
  • 【数据分享】南海综合波浪数据(1945-2018 年)(获取方式看文末)
  • 【历史人物】【王安石】简历与生平
  • win11怎么看本机ip地址?怎么查看代理端口?
  • SAP Datasphere 03 - 数据权限
  • OpenShift AI - 用 Hardware profiles 为运行环境分配可用的硬件规格
  • 什么是股指期货的不对冲策略?
  • 【Flutter】内存泄漏总结
  • HarmonyOS 应用拉起系列(一):应用与元服务互通方式
  • 哔哩哔哩Android视频编辑页的架构升级
  • 二进制数本身没有默认的有符号或无符号解释
  • Eden 和 Survivor 比例可以调整么,参数是什么?还用到了哪些参数?
  • 数新智能 CTO 原攀峰:DataCyber 面向 AI 时代的多模态数据湖设计与实践
  • MYSQL:JDBC编程
  • C语言笔记4:错题整理
  • QT开发---图形与图像(补充)
  • ZYNQ与MPSoC实战:从Vitis入门到项目开发
  • Java学习-运算符
  • HRM论文解读
  • Windows安装虚拟机遇到内容解码失败
  • 【Django】-2- 处理HTTP请求
  • HTTP客户端实现:深入理解Go的net/http包
  • Vue3 + Vite 项目中 API 代理配置问题分析与解决
  • 如何处理Y2K38问题
  • 驾驶场景安全带识别误检率↓76%:陌讯动态特征聚合算法实战解析
  • 【深度学习①】 | Numpy数组篇