一、思路
(1)需要三个参数:deiver驱动对象、外层元素对象、要点击的文本内容
(2)location获取左上角坐标点
(3)size获取外层长宽
(4)得出单页面滑动的起始点和终止点位置(90%、10%)
(5)通过while True一直滑动,直到找到要点击的文本内容
二、源码分析
# 定义加滑动边查找的方法
def swipe_find(driver, element, location):
# 获取滑动的元素坐标点
lc = element.location
# 获取滑动元素的大小
size = element.size
# 初始化元素坐标点的值
x = lc['x']
y = lc['y']
w = size['width']
h = size['height']
startx = x + w * 0.9
starty = y + h/2
endx = x + w * 0.1
while True:
page = driver.page_source # 获取的是整个app页面的信息
try:
driver.find_element(*location).click() # 点击对应的频道信息
return True
except Exception as e:
driver.swipe(startx, starty, endx, starty, duration=2000)
if driver.page_source == page:
print("已经滑动到最后页面,没有找到对应的频道信息!")
return False