1.连接真机后,执行代码时出现错误:A new session could not be created. (Original error: Could not extract PIDs from ps output. PIDS: [], Procs: ["ps: uiautomator"]
解决方案如下:修改Appium ode_modulesappium ode_modulesappium-adblibadb.js 文件
2.代码如下图所示:
from appium import webdriver desired_caps = {} desired_caps['platformName'] = 'Android' #使用哪种移动平台 desired_caps['platformVersion'] = '4.4.4' #指定平台的系统版本 desired_caps['deviceName'] = 'Android Emulator' #启动哪种设备,真机还是模拟器 desired_caps['appPackage'] = 'com.android.calculator2' desired_caps['appActivity'] = '.Calculator' #待测的app的Activity名字 driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps) driver.find_element_by_id('com.android.calculator2:id/digit_1').click() driver.find_element_by_id('com.android.calculator2:id/op_add').click() driver.find_element_by_id('com.android.calculator2:id/digit_2').click() driver.find_element_by_id('com.android.calculator2:id/eq').click() driver.quit()
3.如何确定id,可以通过sdk自带的工具获取,在sdk的tools下的uiautomatorviewer.bat,双击即可运行打开,根据所需要获取的元素,点击,即可获取到id
4.打开Appium Server,Pycharm右键运行即可成功