實現較為累贅,可以把獲取螢幕size,width,height 屬性作為公共屬性單抽出來,不過不影響使用還有可以優化的地方, try: except: 沒有起到我預期的效果,暫時先留著
import time
from mocirepatinet import phoneset
import traceback
class slide():
@staticmethod
def swipeup():
# 獲取螢幕的size
size = phoneset.driver.get_window_size()
print(size)
# 獲取螢幕寬度 width
width = size['width']
print(width)
# 獲取螢幕高度 height
height = size['height']
print(height)
# 執行滑屏操作,向上(上拉)滑動
x1 = width * 0.5
y1 = height * 0.9
y2 = height * 0.25
# time.sleep(2)
print("滑動前")
phoneset.driver.swipe(x1, y1, x1, y2,3000)
print("滑動後")
# 增加滑動次數,滑動效果不明顯,增加滑動次數
for i in range(3):
print("第%d次滑屏" % i)
time.sleep(2)
try:
phoneset.driver.swipe(x1, y1, x1, y2,3000)
except:
print("break")
print(traceback.format_exc())
break
@staticmethod
def swipedown():
# 獲取螢幕的size
size = phoneset.driver.get_window_size()
print(size)
# 獲取螢幕寬度 width
width = size['width']
print(width)
# 獲取螢幕高度 height
height = size['height']
print(height)
# 執行滑屏操作,向下(下拉)滑動
x1 = width * 0.5
y1 = height * 0.25
y2 = height * 0.9
# time.sleep(2)
print("滑動前")
phoneset.driver.swipe(x1, y1, x1, y2, 3000)
print("滑動後")
# 增加滑動次數,滑動效果不明顯,增加滑動次數
for i in range(3):
print("第%d次滑屏" % i)
time.sleep(3)
try:
phoneset.driver.swipe(x1, y1, x1, y2, 3000)
except:
print("break")
print(traceback.format_exc())
break
# time.sleep(3)
@staticmethod
def swipeleft():
# 獲取螢幕size
size = phoneset.driver.get_window_size()
print(size)
# 獲取螢幕寬度
width = size['width']
print(width)
# 獲取螢幕高度
height = size['height']
print(height)
# 執行左滑操作,(向左)滑動
x1 = width*0.8
x2 = width*0.2
y1 = height*0.5
# 滑動前
phoneset.driver.swipe(x1,y1,x2,y1,2000)
# 滑動後
for i in range(1):
print("第%d次滑屏"% i)
time.sleep(2)
phoneset.driver.swipe(x1,y1,x2,y1,2000)
@staticmethod
def swiperight():
# 獲取螢幕size
size = phoneset.driver.get_window_size()
print(size)
# 獲取螢幕寬度width
width = size['width']
# 獲取螢幕高度height
height = size['height']
x1 = width*0.2
x2 = width*0.8
y1= height*0.5
# 滑動前操作,向右滑動
phoneset.driver.swipe(x1,y1,x2,y1,2000)
# 滑動後
for i in range(2):
print("第%d次滑動"%i)
time.sleep(2)
phoneset.driver.swipe(x1,y1,x2,y1,2000)
python appium實現企業微信自動打卡
import time def init self,desired caps,image name self.url self.driver webdriver.remote self.url,desired caps self.driver.implicitly wait 10 self.desi...
Python Appium實現滑動引導頁進入APP
1 建立session 2 運用 模擬手指從右向左滑動的操作 獲取螢幕寬度和高度 def getsize self x self.driver.get window size width y self.driver.get window size height return x,y 向左滑動 def...
python appium實現頁面元素的滑動
畢竟,比較熟悉robotframework這個工具。現在在複習python語言,就搞半天。思路有,函式用swipe,也知道。頁面就是不滑動,有點尷尬了。函式也沒有什麼錯誤,最後發現錯在自己在頁面上找的元素的思路上。思路確定後,就找到他們各自的座標就可以了。總結 思路沒有錯,動手執行後,問題就解決了。...