左右滑都可以,上滑操作swipe_on("up")不生效,一到这个动作就退出,而且没看见报错,请老师帮忙看下,谢谢!!
来源:1-10 driver和滑动函数封装结合

慕仰2574326
2018-07-22
# 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可以不维护该参数,如果系统找不到可以维护
"noReset": "true"
}
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,3000)
#向下滑动
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()
time.sleep(1)
swipe_on("left")
time.sleep(1)
swipe_on("left")
time.sleep(1)
swipe_on("right")
time.sleep(1)
swipe_on("left")
time.sleep(1)
swipe_on("up")
# driver.swipe(300,900,300,100,2000)
time.sleep(10)
2回答
-
Mushishi
2018-07-23
你看,他已经执行了,只是你在界面没看到结果,你可以去更改一下你滑动的参数,就是按比例多少
032018-07-31 -
慕仰2574326
提问者
2018-07-22
原生的方法也试了还是不行,困惑。。。driver.swipe(300,900,300,100,2000)
00
相似问题