driver.get_window_size() 获取屏幕的宽、高;
driver.swipe()从坐标1滑动到坐标2,t毫秒时间内完成。
上下滑动时,坐标的x值可以不变,只改变坐标y值的大小。
左右滑动时,坐标的y值可以不变,只改变坐标x值的大小。
上下滑动的代码:
try:
#等待列表出现,超时为6s
WebDriverWait(self.driver,6).until(EC.visibility_of_element_located((By.ID,"com.android.contacts:id/menu_search")))
print(self.driver.get_window_size())
x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
print x,y
#上滑
self.driver.swipe(x/2,y*3/4, x/2, y/4, 200)
#self.driver.swipe(100, 1400, 100, 800, 200)
sleep(5)
#下滑
self.driver.swipe(x/2,y/4, x/2, y*3/4, 200)
except Exception,e:
print e
else:
print "run sucess swipe up and down "