码迷,mamicode.com
首页 > 移动开发 > 详细

Python 简单的安卓操作

时间:2020-01-17 21:17:24      阅读:44      评论:0      收藏:0      [点我收藏+]

标签:ecif   简单的   open   col   default   存在   edit   UNC   more   

from uiautomator import Device
from PIL import Image
import math
import operator
from functools import reduce

## image compare.
# def image_compare(img1,img2):
#     image1 = Image.open(img1)
#     image2 = Image.open(img2)
#
#     his1 = image1.histogram()
#     his2 = image2.histogram()
#     result = math.sqrt(reduce(operator.add,list(map(lambda a,b: (a-b)**2,his1,his2)))/len(his1))
#     # result bigger,the difference is more big
#     print(result)
# image_compare(r‘C:\Users\mats\Desktop\on.png‘,r‘C:\Users\mats\Desktop\of.png‘)


# d = Device(‘0185ca9b35780dc9‘)
# print(d.info)
# d.screen.on()

# if d.screen == "on":  # of d.screen != "off"
#     d.screen.off()
# elif d.screen == "off":  # of d.screen != "on"
#     d.screen.on()

# d.press.home()
# d.press.back()
# d.press("back")

# d.click(200,500)
# d.long_click(x, y)
# d(textContains=‘Bluetooth‘).click()
# d(text="Settings").click()
# d(text="Settings").long_click()

# d.swipe(100, 10, 100, 1400)

## Two point gesture ;   ((sx1, sy1), (sx2, sy2)) \.to((ex1, ey1), (ex2, ey2))
# d().gesture((200, 300), (300, 300)) \
#                   .to((100, 300), (900, 300))

# d.drag(sx, sy, ex, ey)
# d(text="Settings").drag.to(x, y, steps=100)
# ## drag the ui object to another ui object(center)
# d(text="Settings").drag.to(text="Clock", steps=50)

# d.screenshot("home.png")

## click a list object which has on/off button, so you choose its list first,then click its child object 开关按钮
# d(className="android.widget.LinearLayout", resourceId="com.android.settings:id/switch_bar") \
#   .child(className="android.widget.Switch") \
#   .click()

## select on/off button on the right side of "off", same as the above one. 开关按钮
# d(text="Off").right(className="android.widget.Switch").click()

## scroll to find some element,need to find the list first,then scroll in the list to find the child element 滚动查找
# d(className="android.widget.ListView", resourceId="android:id/list") \
#  .child_by_text(
#     "GMInfo3",
#     allow_scroll_search=True,
#     className="android.widget.TextView"
#   ).click()

## element exists 判断是否存在
# d(text="Settings").exists # True if exists, else False
# d.exists(text="Settings") # alias of above property.

## Set/Clear text of editable field  文本框改字
# d(text="fg").clear_text()
# d(text="To").set_text("My text...")  # set the text

# scroll forward(default) vertically(default)
# d(scrollable=True).scroll(steps=2)
# # scroll forward horizentally
# d(scrollable=True).scroll.horiz.forward(steps=100)
# # scroll backward vertically
# d(scrollable=True).scroll.vert.backward()
# # scroll to beginning horizentally
# d(scrollable=True).scroll.horiz.toBeginning(steps=100, max_swipes=1000)
# # scroll to end vertically
# d(scrollable=True).scroll.toEnd()
# # scroll forward vertically until specific ui object appears
# d(scrollable=True).scroll.to(text="Security")

Python 简单的安卓操作

标签:ecif   简单的   open   col   default   存在   edit   UNC   more   

原文地址:https://www.cnblogs.com/wztshine/p/12207243.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!