今天我在使用appium的defind_element时遇到了一些问题,就是网上课程寻找元素的方式都是find_element_by_xpath,而我用这个方法却失效了然后我就查看appium的defind_element的源码:
:然后我比较了我还以为是这个格式 :
phone.find_element('AppiumBy.ID','com.tencent.mobileqq:id/j_k').click()
结果发现还是无效,然后我就类比一下selenium,觉得应该是要引入这个:
from selenium.webdriver.common.by import By
然后用这个格式:
phone.find_element(By.ID,'com.tencent.mobileqq:id/j_k').click()
但我把selenium直接替换成appium却还是无效,再尝试了一波才知道它们是有一点区别的,appium应该是这样引入By的:
from appium.webdriver.common.appiumby import By
然后再用这个格式找元素就可以了:
phone.find_element(By.ID,'com.tencent.mobileqq:id/j_k').click() 总结: from appium.webdriver.common.appiumby import By #导入库 phone.find_element(By.ID,'com.tencent.mobileqq:id/j_k').click()