随笔 - 2  文章 - 0  评论 - 0  阅读 - 8259

appium报错AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'解决方法

解决方法:

from appium.webdriver.common.appiumby import AppiumBy # 导入AppiumBy
search = driver.find_element(AppiumBy.ID,"com.android.settings:id/search") # 编写格式:driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='accessibility_id')

思考流程:
1.敲代码时,编辑器已经标黄提示无find_element_by_id,当时以为是敲错,复制了正确的代码运行,报“AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'”
2.查看网上解决方案,有人提到现在的版本不支持find_element_by_id,目前写法为driver.find_element(By.ID,"com.android.settings:id/search"),修改后运行,仍然报错
3.ctrl+查看find_element方法,直接复制注释中的driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='accessibility_id'),AppiumBy报错
4.找到https://blog.csdn.net/fsafd3321/article/details/127096420博客中的解决方法,尝试后,能成功运行。但是解决思路中,提到的文件中搜索关键词这步不会
5.反推第三步,应该这样看,ctrl+查看find_element方法,然后由于AppiumBy报错,应该再点击查看find_element中的AppiumBy类,或全文搜索AppiumBy可看到导入的
from appium.webdriver.common.appiumby import AppiumBy




参考博客:
https://www.cnblogs.com/liuyuelinfighting/p/15677738.html
https://blog.csdn.net/fsafd3321/article/details/127096420
posted on   十一幺  阅读(7699)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

levels of contents 点击查看具体代码内容
点击右上角即可分享
微信分享提示