appium+python:螢幕滑動功能;簡單實用很流皮
前提環境已搭建;好了直接上程式碼
# 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)