#调用方式
Roll_ele ("ID", "ele_id", "7", "Up", 3) #将控件分为7格, swipe up 3 from the bottom-down second grid
#滑动控件的方法
defRoll_ele (id,ele_id,size,direct,rollsize=1): """The parameter ID is positional, eled_id is the ID of the specific control or XPath, etc., the size of the control needs to be divided into a few cells, direct is the sliding direction, up or down (top or bottom), rollsize to slide a few, the parameter value range is (1,size-2 ) """ #The following is a swipe of the document detail data----------------------------------------------------------------------------Ele_=Element (id,ele_id) #Element为自己包装的一个定位控件的类 Start_loc= Ele_.get_location_start ()#gets the start coordinates of the control, Get_location_start () a method for getting the start and end coordinates of the control for itself, Appium directly to Element.location, and the returned type is dict,{' x ': 520, ' Y ' : 1230}Size_ele= Ele_.get_ele_size ()#gets the size of the control, Get_ele_size () writes a method of getting control size for itself, appium directly to Element.size, the returned type is dict, such as {' Height ': 589, ' width ': +} #coordinates of the center above the controlEle_start =[] ele_start.append (float (start_loc['x']) +float (size_ele['width'])/2) Ele_start.append (float (start_loc['y'])) #coordinates of the center below the controlEle_end =[] ele_end.append (float (start_loc['x']) +float (size_ele['width'])/2) Ele_end.append (float (start_loc['y']) +float (size_ele['Height'])) #The control column has a size row, each sliding 1/size, i.e. size_ele[' height ']/size lengthPer_height = Float (size_ele['Height'])/size#height of each cell #if up, when sliding, slide to the coordinates of the top rollsize grid each time from the second-to-last coordinate (because sliding directly from the bottom of the control does not slide, it will fail); ifdirect==' up': #swipe_to为自己包装的driver. Swipe () method swipe_to (ele_end[0],ele_end[1]-per_height,ele_end[0],ele_end[1]-per_height-rollsize*per_height,1000) Else: swipe_to (ele_start[0],ele_start[1]+per_height,ele_start[0],ele_start[1]+per_height+rollsize*per_height,1000) Time.sleep (1)
Appium+python: How to write a sliding control by yourself