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

发布时间 2023-06-29 10:37:03作者: 十一幺

解决方法:

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