老师,为什么我的上滑操作没有生效?也没报错,您之前视频中也有这个问题,最后怎么解决的?
# coding:utf-8
from appium import webdriver
import time
def get_driver():
capabilities = {
"platformName": "Android", #设备系统
"deviceName": "127.0.0.1:21503", #adb devices 命令下的设备编号
"app": "C:\\mukewang.apk", #apk地址
"appActivity": "cn.com.open.mooc.index.splash.GuideActivity" #程序入口,1.7版本以上的Appium可以不维护该参数,如果系统找不到可以维护
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",capabilities)
return driver
#获取屏幕的宽和高
def get_size():
size = driver.get_window_size()
width = size["width"]
height = size["height"]
return width,height
#向左边滑动
def swipe_left():
x1 = get_size()[0]/10*9
y1 = get_size()[1]/2
x = get_size()[0]/10
driver.swipe(x1,y1,x,y1,2000)
#向右边滑动
def swipe_right():
x1 = get_size()[0]/10
y1 = get_size()[1]/2
x = get_size()[0]/10*9
driver.swipe(x1,y1,x,y1,2000)
#向上滑动
def swipe_up():
x1 = get_size()[0]/2
y1 = get_size()[1]/10*9
y = get_size()[1]/10
driver.swipe(x1,y1,x1,y,2000)
#向下滑动
def swipe_down():
x1 = get_size()[0]/2
y1 = get_size()[1]/10
x = get_size()[0]/10*9
driver.swipe(x1,y1,x1,y,2000)
def swipe_on(direction):
if direction == "up":
swipe_up()
elif direction == "down":
swipe_down()
elif direction == "left":
swipe_left()
else:
swipe_right()
driver = get_driver()
swipe_on("left")
swipe_on("left")
swipe_on("right")
swipe_on("left")
swipe_on("up")
time.sleep(10)