1,滑动
from time import sleep # 获取屏幕大小 def getSize(self): x = self.driver.get_window_size()['width'] y = self.driver.get_window_size()['height'] return (x, y) #向左滑动 def swipeLeft(self,t): l=self.getSize() x1=int(l[0]*0.75) y1=int(l[1]*0.5) x2=int(l[0]*0.25) self.driver.swipe(x1,y1,x2,y1,t) #向右滑动 def swipeRight(self,t): l=self.getSize() x1=int(l[0]*0.25) y1=int(l[1]*0.5) x2=int(l[0]*0.75) self.driver.swipe(x1,y1,x2,y1,t) #向上滑动 def swipeUp(self,t): l=self.getSize() x1=int(l[0]*0.5) y1=int(l[1]*0.8) y2=int(l[1]*0.4) self.driver.swipe(x1,y1,x1,y2,t) #向下滑动 def swipeDown(self,t): l=self.getSize() x1=int(l[0]*0.5) y1=int(l[1]*0.25) y2=int(l[1]*0.75) self.driver.swipe(x1,y1,x1,y2,t) #查找元素,没找到滑动 def findLocal(self): x=1 while x==1: if self.fact()==1: self.swipeUp(2000) sleep(2) self.fact() else: print ('找到了') x=2
2,递归
def fact(self): n =1 try: self.driver.find_element_by_id('cn.com.open.mooc:id/tv_replace').click() except Exception: return n
3,递归
def fact(n): if n==1: return 1 else: return n*fact(n-1) cont=fact(5) print (cont) # print (fact(5))