appium报错AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'解决方法
1.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
合集:
appium
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统