前提环境已搭建;好了直接上代码
# coding=utf-8 import time,unittest from appium import webdriver
desired_caps = { 'platformName': 'Android', 'deviceName': '91QEBNS2Y6WW1232', 'platformVersion': '5.0', 'appPackage': '填写你自己的', # apk包名 'appActivity': '填写你自己的', 'unicodeKeyboard': True, # 屏蔽软键盘 'resetKeyboard': True } driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(5)
#进入主页面后,要滑动页面执行下面
def swipeUp(driver, t=500, n=1): '''向上滑动屏幕''' l = driver.get_window_size() x1 = l['width'] * 0.5 # x坐标 y1 = l['height'] * 0.75 # 起始y坐标 y2 = l['height'] * 0.25 # 终点y坐标 for i in range(n): driver.swipe(x1, y1, x1, y2, t) #或者 def swipeDown(driver, t=500, n=1): '''向下滑动屏幕''' l = driver.get_window_size() x1 = l['width'] * 0.5 # x坐标 y1 = l['height'] * 0.25 # 起始y坐标 y2 = l['height'] * 0.75 # 终点y坐标 for i in range(n): driver.swipe(x1, y1, x1, y2,t)首发,不喜勿喷。