swipe滑动操作

1.swipe() 滑动用法
  • Swipe(x1,y1,x2,y2,duration)
  • x1-开始滑动的x坐标,y1-开始滑动的Y坐标
  • x2-结束点x坐标,y2-结束点y坐标
  • duration滑动事件(默认5毫秒)
#coding=utf-8

from appium import webdriver

import time

# 定义启动设备需要的参数
desired_caps = {
"platformName": "Android", #手机系统
"deviceName": "127.0.0.1:62001",#设备名称,在dos输入adb devices获取
"platformVersion": "5.1.1", #手机系统版本
"appPackage": "com.yw.yzz", #包名(#在dos下进入xxx.apk所存在的文件夹中,输入aapt dump badging xxx.apk获取)
"appActivity": "com.yw.yzz.biz.splash.SplashActivity",#APP活动(#在dos下进入xxx.apk所存在的文件夹中,输入aapt dump badging xxx.apk获取)
"unicodeKeyboard": "True",#使用appium的输入法,支持中文并隐藏键盘
"resetKeyboard": "True", #将输入法重置回设备默认的输入法
"noReset": "True"#appium启动app时会自动清除app里面的数据,noReset=True就是启动app不清除数据
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
#代码脚本和服务端是通过  http://127.0.0.1:4723/wd/hub 来进行通信的(固定格式)

time.sleep(1)
print(driver.get_window_size())#打印屏幕高和宽
time.sleep(2)

#向左滑动引导页
y = 0
while y < 3:
    driver.swipe(350, 900, 350, 100, 1000)
    time.sleep(1)
    y += 1
    time.sleep(1)
driver.find_element_by_id("com.yw.yzz:id/btn_open").click()
time.sleep(4)
driver.find_element_by_id("com.yw.yzz:id/recyclerview").click()
driver.find_element_by_id("com.yw.yzz:id/recyclerview").click()
driver.find_element_by_id("com.yw.yzz:id/recyclerview").click()
driver.find_element_by_id("com.yw.yzz:id/seting_tab").click()
driver.find_element_by_id("com.yw.yzz:id/fragment_my_nickname").click()
driver.find_element_by_id("com.yw.yzz:id/login_name").send_keys("17779828883")
driver.find_element_by_id("com.yw.yzz:id/login_identify_code").send_keys("123456")
driver.find_element_by_id("com.yw.yzz:id/btn_login").click()
#coding=utf-8

from appium import webdriver
from time import sleep

caps = {
  "platformName": "Android",
  "deviceName": "127.0.0.1:62001",
  "platformVersion": "5.1.1",
  "appPackage": "com.yw.yzz",
  "appActivity": "com.yw.yzz.biz.splash.SplashActivity",
  "unicodeKeyboard": "True",
  "resetKeyboard": "True"
  # "noReset": "True"
}
driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘,caps)

def size():
   x=driver.get_window_size()["width"]#获取当前屏幕的宽
   y=driver.get_window_size()["height"]#获取当前屏幕的高
   return (x,y)

#上滑
def up(t):
    sz=size()
    x1=int(sz[0]*0.5)
    y1=int(sz[1]*0.9)
    y2=int(sz[1]*0.2)
    driver.swipe(x1,y1,x1,y2,t)
    sleep(1)
    return driver

#下滑
def down(t):
    sz=size()
    x1=int(sz[0]*0.5)
    y1=int(sz[1]*0.2)
    y2=int(sz[1]*0.9)
    driver.swipe(x1,y1,x1,y2,t)
    sleep(1)
    return driver

#左滑
def left(t):
    sz=size()
    x1=int(sz[0]*0.9)
    x2=int(sz[0]*0.2)
    y1=int(sz[1]*0.5)
    driver.swipe(x1,y1,x2,y1,t)
    sleep(1)
    return driver

#右滑
def right(t):
    sz=size()
    x1=int(sz[0]*0.2)
    x2=int(sz[0]*0.9)
    y1=int(sz[1]*0.5)
    driver.swipe(x1,y1,x2,y1,t)
    sleep(1)
    return driver

相关推荐