安卓脚本
查看已经连接的设备名
adb devices
有线的话,手机开usb调试就连上了
无线连接:
adb connect 192.168.20.205:5555
ip地址,在设置中搜索
后面的端口,可以用adb tcpip 5555
设置
这是无线调试
获取当前应用名
adb shell dumpsys window | grep mCurrentFocus
mCurrentFocus=Window{9a30490 u0 com.android.settings/com.android.settings.Settings}
包名package:
com.android.settings
界面名activity
com.android.settings.Settings
获取日志
adb logcat
进行操作会更新日志,可以追踪bug
一般在at这里,开头是E
appium
打开端口
appium &
默认打开0.0.0.0:4723
,或者想要手写:
appium –a 0.0.0.0 –p 4723
查看端口
lsof -i:4723
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 72563 joey 24u IPv4 0x1798b0f4e6e37c23 0t0 TCP *:4723 (LISTEN)
关掉端口
kill -9 <端口pid>
跳转应用
driver.start_activity(包名, 界面名)
应用放在后台一会
# 放后台一会再自动回到前台(点home键)
driver.background_app(seconds)
UIAutomatorViewer
要用jdk8才行

点一下第二个,要啥有啥
获取名字和地址
定位元素
通过
resource-id
定位
driver.find_element_by_id(id_value)
id作为字符串传入
class
driver.find_element_by_class(class_value)
x-path
driver.find_element_by_xpath(xpath_value)
例子:
# 点击放大镜
search_button = driver.find_element_by_id('com.android.settings:id/search_action_bar')
search_button.click()
# 输入
input = driver.find_element_by_id('android:id/search_src_text')
input.send_keys("hello")
# 点击返回
driver.find_element_by_xpath("//*[@content-desc='Navigate up']").click()
从上往下找,返回第一个

找不到对应元素
elements返回一组元素,如果找不到是空数组,不会报错
element找单个,就会报错
等待
如果页面没刷出来,找不到,会报错
因此要等一下
隐式等待
所有元素设置等待时长,找到了马上操作,找不到就等着
设置一次,全局通用
driver.implicitly_wait(5)
滑动
driver.swipe(start_x, start_y, end_x, end_y, duration)
屏幕距离左边是x,上面是y
滑动会有误差
小米6
进入开发者模式
设置》我的设备〉全部参数》miui版本多次点击
设置〉更多设置》可以看到开发者选项了
设备号
5e518110
设置
com.android.settings
com.android.settings.MainSettings
钉钉
com.alibaba.android.rimet
com.alibaba.android.rimet.biz.LaunchHomeActivity
打开钉钉
adb shell am start -n com.alibaba.android.rimet/com.alibaba.android.rimet.biz.LaunchHomeActivity
点击1
x:[500, 580]
y:[1792, 1870]
adb shell input tap 530 1800
点击2
x:[587, 746]
y:[1216, 1419]
adb shell input tap 600 1300
adb安装:
adb install /Users/joey/Downloads/Tasker.5.8.2.apk
路径是本地apk路径
然后手机上点确定
https://www.jianshu.com/p/69223eab8038
bug
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: e android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS permission to use the PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS flag'; Code: '1' Error executing adbExec. Original error: 'Command '/Users/joey/Library/android/sdk/platform-tools/adb -P 5037 -s 5e518110 shell pm install -g /data/local/tmp/appium_cache/12bb63270ecd4315cfaaa8d8202b809bbfccca11.apk' exited with code 1'; Stderr: 'Error: java.lang.SecurityException: You need th
要打开安装权限,包括安全调试
会让你装一堆东西
abd传送文件
adb push /Users/joey/Study/Android/appium\ hello/open.py /sdcard
直接扔到/sdcard/
下面
temux
命令行
/storage/emulated/0/qpython/scripts3
/storage/emulated/0/sl4a/scripts
/storage/
ssh连手机
参考
Last updated
Was this helpful?