appium常用 的操作

1.滑动

#获取屏幕的分辨率 (返回的是字典)
screen_x = driver.get_window_size()['width']
screen_y = driver.get_window_size()['height']

def swipe_up(distane):
    # 起点坐标
    start_x = screen_x / 2
    start_y = screen_y / 4 * 3
    # 终点坐标
    end_x = start_x
    end_y = start_y - distane
    if end_y <=0:
        raise Exception('滑动距离过大,超过屏幕范围')
    for i in range(5):
        driver.swipe(start_x,start_y,end_x,end_y,2000)

swipe_up(600)
  1. 拖拽
# 拖拽
# 获取拖拽目标
source=driver.find_element_by_xpath('//*[@text="日历"]')
# 获取拖动终点区域

target=driver.find_element_by_xpath('//*[@text="文件管理"]')
# 开始拖动
driver.drag_and_drop(source,target)

3.按键

# 返回桌面
driver.keyevent(3)

# 增加音量
time.sleep(3)
for i in range(3):
    driver.keyevent(24)
# 减小音量
time.sleep(3)
for i in range(3):
    driver.keyevent(25)
time.sleep(3) # 等待

# 长按home键---交互效果和手机系统相关
driver.long_press_keycode(3)

4.切换和点击

#切换到baidu
 #adb shell dumpsys activity recents | findstr intent={
   查看包名 和入口信息
driver.start_activity('包名','入口信息')
driver.start_activity('com.kugou.android','.app.splash.SplashActivity')
# 4.点击跳过广告
driver.tap([(940, 130)]) # 坐标点击
posted @ 2021-03-21 17:10  太白之魔童降世  阅读(134)  评论(0编辑  收藏  举报