一、获取手机id
略过基础环境配置,前面博客有介绍。通过adb devices查看
![595108a69180e392c9fb3ef0f5ac3ce0.png](https://img-blog.csdnimg.cn/img_convert/595108a69180e392c9fb3ef0f5ac3ce0.png)
唯一id:db3dc449
二、获取appPackage、appActivity
参考https://mp.csdn.net/postedit/95105457
三、连接APP客户端(app-desktop)
1、启动程序
![5f0c87be7f282bccec5d9c1325d592e6.png](https://img-blog.csdnimg.cn/img_convert/5f0c87be7f282bccec5d9c1325d592e6.png)
2、打开搜索
![df23bcab960f3edf5ba1b493732b14fe.png](https://img-blog.csdnimg.cn/img_convert/df23bcab960f3edf5ba1b493732b14fe.png)
3、添加配置
![270c5be25f770c1cdf0599a41063f772.png](https://img-blog.csdnimg.cn/img_convert/270c5be25f770c1cdf0599a41063f772.png)
4、启动应用程序,填入正确的信息后,点击startSession
![58b3ed8143313604b655498932425549.png](https://img-blog.csdnimg.cn/img_convert/58b3ed8143313604b655498932425549.png)
5、启动成功后,先点击目标元素再点击筛选,更新页面动态
![d72e438a402b1afe5a847524c0c24ec7.png](https://img-blog.csdnimg.cn/img_convert/d72e438a402b1afe5a847524c0c24ec7.png)
四、定位元素
1、id定位
选择APP中的页面元素,查看右侧的Selected Element。会发现参数id,往下拉还会有resource-id,会发现他们两个是一样的。这就是说明,这个id是唯一的(如果只有resource-id,没有id,说明resource-id不是唯一的,也就是不能通过id定位方式定位元素. ,id一定要用双引号括起来),定位代码:driver.find_element_by_id('');
![ea042516b59e299772d2e2f3d305c92e.png](https://img-blog.csdnimg.cn/img_convert/ea042516b59e299772d2e2f3d305c92e.png)
2、xpath定位
选择APP页面元素,查看右侧Selected Element,找到对应的xpath。定位代码:driver.find_element_by_xpath(")
![a19d00a28f05dafb47159669fa71183a.png](https://img-blog.csdnimg.cn/img_convert/a19d00a28f05dafb47159669fa71183a.png)
当然还有很多其他定位元素方法,这里不一一介绍,上面两种方法可满足常规使用