滑动操作--左滑右滑上滑下滑

#encoding:utf-8

from time import sleep

from find_element.capabilityimport driver

from selenium.webdriver.support.uiimport WebDriverWait

WebDriverWait(driver,3).until(lambda x:x.find_element_by_xpath("//*[@text='互动']"))

# driver.find_element_by_xpath("//*[@text='互动']").click()

#获取屏幕尺寸

def get_size():

# print(driver.get_window_size())

    x=driver.get_window_size()["width"]

y=driver.get_window_size()["height"]

return x,y

#显示屏幕尺寸(width,height)

l = get_size()

print("获取屏幕尺寸",l)

#向左滑动

def swipeLeft():

l=get_size()

x1 =int(l[0]*0.9)

x2 =int(l[0]*0.1)

y1 =int(l[1]*0.2)

print("开始向左滑动")

#从x1y1 滑动到x2y1

    driver.swipe(x1,y1,x2,y1)

#向右滑动

def swipeRight():

l=get_size()

x1 =int(l[0]*0.1)

x2 =int(l[0]*0.9)

y1 =int(l[1]*0.2)

print("开始向右滑动")

# 从x1y1 滑动到x2y1

    driver.swipe(x1,y1,x2,y1)

#向上滑动

def swipeUp():

l=get_size()

y1 =int(l[1]*0.1)

y2 =int(l[1]*0.9)

x1 =int(l[0]*0.5)

print("向上滑动")

#start_x - 滑动开始x轴坐标

#start_y - 滑动开始y轴坐标

#end_x - 滑动结束x轴偏移量

#end_y - 滑动结束y轴偏移量

#duration - (可选) 执行此次滑动时间,单位毫秒.

    driver.swipe(x1,y2,x1,y1,1500)

#向下滑动

def swipeDown():

l = get_size()

y1 =int(l[1]*0.1)

y2 =int(l[1]*0.9)

x1 =int(l[0] *0.5)

print("向下滑动")

driver.swipe(x1,y1,x1,y2,2000)

#向左滑动两次

# for i in range(2):

#    swipeLeft()

#    sleep(0.5)

#向右滑动两次

# for i in range(2):

#    swipeRight()

#    sleep(0.5)

#向上滑动两次

for iin range(2):

swipeUp()

sleep(0.5)

swipeDown()

你可能感兴趣的:(滑动操作--左滑右滑上滑下滑)