{ "cells": [ { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "手机型号:ONEPLUS A5010\n" ] } ], "source": [ "import time\n", "import uiautomator2 as u2\n", "\n", "\n", "d = u2.connect_wifi('192.168.10.136')\n", "\n", "print('手机型号:'+d.device_info['model'])\n", "## 我\n", "my = d.xpath('//*[@text=\"我\"]')\n", "my = d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/root_view\"]/android.widget.FrameLayout[5]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]')\n", "my.click()\n", "## 判断是否出现 编辑资料 出现则表示在我的页面\n", "d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/ht7\"]')\n", "\n", "## 我的抖音号\n", "d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/l1c\"]')\n", "## 获赞\n", "d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/b4o\"]')\n", "## 粉丝数\n", "d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/c__\"]')\n", "## 我的关注\n", "d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/c-d\"]')\n", "\n", "## 右上角打开侧边栏按钮\n", "info = d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/ghv\"]')\n", "info.click()\n", "## 点击侧边栏的创作中心\n", "d.xpath('//*[@text=\"创作者服务中心\"]').click()\n", "\n", "d.xpath('//*[@text=\"商品橱窗\"]').click()\n", "\n", "## 这个是广告 后面处理\n", "d.xpath('//*[@text=\"稍后再看\"]').click()\n", "\n", "d.xpath('//*[@text=\"选品广场\"]').click()\n", "\n", "d.xpath('//*[@text=\"服饰内衣\"]')\n", "## 通过右上角 搜索后面的链接判断是否进入页面 此处应该等于 链接\n", "d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[1]/android.view.View[3]')\n", "d.xpath('//*[@text=\"链接\"]')\n", "\n", "## 点击子分类进入商品页\n", "d.xpath('//*[@text=\"裤子\"]')\n", "## 可以用于判断商品列表页面是否打开\n", "text = d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[1]/android.view.View[2]')\n", "d.xpath('//*[@text=\"推荐\"]')\n", "## 这个地方是推荐就代表打开了商品列表页面\n", "d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[2]/android.view.View[1]')\n", "## 第一个是筛选栏 所以要-1\n", "good_num = d.xpath('//*[@resource-id=\"app\"]/android.view.View').all()\n", "## 判断是否打开了商品详情页 如果打开页面标题应该为 商品推广信息\n", "d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/title\"]')\n", "## 售价\n", "m_money = d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[1]/android.view.View[2]/android.view.View[3]/android.view.View[3]')\n", "store_name = d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[1]/android.view.View[14]/android.view.View[1]/android.view.View[1]/android.view.View[2]/android.view.View[1]')\n", "## 预计每当赚 后面三个分别为 百十个位 小数点 小数位\n", "lirun = d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[1]/android.view.View[2]/android.view.View[1]/android.view.View[3]')\n", "## 点击联系客服\n", "d.xpath('//*[@text=\"联系商家\"]')\n", "## 判断是否进入客服页面\n", "d.xpath('//*[@resource-id=\"web-im-container\"]')\n", "## 电话按钮\n", "d.xpath('//*[@resource-id=\"web-im-container\"]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[2]/android.view.View[4]/android.view.View[1]')\n", "## 出现联系商家\n", "d.xpath('//*[@text=\"联系商家\"]')\n", "## 这里是电话沟通 还是 查看商家联系方式\n", "d.xpath('//android.widget.ListView/android.view.View[1]/android.view.View[2]')\n", "## 如果是联系方式 则点击查看\n", "d.xpath('//*[@text=\"查看商家联系方式\"]')\n", "## 点击 复制号码\n", "d.xpath('//*[@text=\"复制号码\"]')\n", "## 通过剪贴板获取\n", "print(d.clipboard)\n", "## 可以清空剪贴板\n", "d.set_clipboard('text', 'label')\n", "\n", "## 点击弹出联系方式的取消\n", "d.xpath('//*[@text=\"取消\"]')\n", "## 返回两次到达商品列表页\n", "d.press(\"back\")\n", "d.press(\"back\")\n", "\n", "all_type = d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]/android.view.View[2]/android.view.View[1]/android.view.View[1]/android.view.View[2]')\n", "all_type.click()\n", "\n", "one_type = d.xpath('//*[@text=\"食品饮料\"]')\n", "## 滑动侧栏\n", "\n", "\n", "d.HTTP_TIMEOUT = 60 # 默认值60s, http默认请求超时时间\n", "\n", "# 当设备掉线时,等待设备在线时长,仅当TMQ=true时有效,支持通过环境变量 WAIT_FOR_DEVICE_TIMEOUT 设置\n", "d.WAIT_FOR_DEVICE_TIMEOUT = 70 \n", "\n", "d(text=\"Settings\").exists # True if exists, else False\n", "d.exists(text=\"Settings\") # alias of above property.\n", "\n", "# advanced usage\n", "d(text=\"Settings\").exists(timeout=3) # wait Settings appear in 3s, same as .wait(3)\n", "\n", "d(text=\"Settings\").get_text() # get widget text\n", "d(text=\"Settings\").set_text(\"My text...\") # set the text\n", "d(text=\"Settings\").clear_text() # clear the text\n", "\n", "## Swipe from the center of the UI object to its edge\n", "\n", "## Swipe supports 4 directions:\n", "## left\n", "## right\n", "## top\n", "## bottom\n", "d(text=\"Settings\").swipe(\"right\")\n", "d(text=\"Settings\").swipe(\"left\", steps=10)\n", "d(text=\"Settings\").swipe(\"up\", steps=20) # 1 steps is about 5ms, so 20 steps is about 0.1s\n", "d(text=\"Settings\").swipe(\"down\", steps=20)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# coding: utf-8\n", "#\n", "import uiautomator2 as u2\n", "from uiautomator2 import Direction\n", "\n", "d = u2.connect('192.168.10.136')\n", "#d.debug = True\n", "print(d.app_current())\n", "print(d.device_info)\n", "#d.click(0.525, 0.151)\n", "#d.swipe_ext(\"up\", scale=0.9)\n", "#d.app_list_running()\n", "#d(text=\"Settings\").swipe(\"down\", steps=20)\n", "\n", "stores = d.xpath('//*[@resource-id=\"app\"]/android.view.View').all()\n", "#store_count = count(stores)\n", "#print(store_count)\n", "#d.swipe_points([(200,1000),(250,500),(250,100)],0.2)\n", "\n", "\n", "for store in stores:\n", " good_attrib = store.elem.find('./android.view.View[2]')\n", " good_name = good_attrib.attrib['text']\n", " print(good_name)\n", " if good_name != '':\n", " store.click()\n", " \n", " title = d.xpath('//*[@resource-id=\"com.ss.android.ugc.aweme:id/title\"]').get_text()\n", " z_money1 = d.xpath('//*[@text=\"预估每单赚\"]').parent().elem.find('./android.view.View[3]').attrib['text']\n", " z_money2 = d.xpath('//*[@text=\"预估每单赚\"]').parent().elem.find('./android.view.View[5]').attrib['text']\n", " z_money = z_money1 + '.' + z_money2\n", " m_money = d.xpath('//*[@text=\"售价\"]').parent().elem.find('./android.view.View[3]').attrib['text']\n", " d.xpath('//*[@resource-id=\"app\"]/android.view.View[1]').scroll_to(\"进店逛逛\")\n", " store_name = d.xpath('//*[@text=\"进店逛逛\"]').parent().elem.find('./android.view.View[1]/android.view.View[2]').attrib['text']\n", " print(z_money,m_money,store_name)\n", " d(resourceId=\"com.ss.android.ugc.aweme:id/bbf\").click()\n", " # 按下back键的常规方式\n", " #d.swipe_ext(\"down\")\n", "\n", "#print(d(resourceId=\"//*[@resource-id=\"wall-warper\"]/android.view.View[2]/android.view.View[1]/android.widget.Button\").count)\n", "#d.send_keys(\"back\", clear=True)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:root] *", "language": "python", "name": "conda-root-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }