Appium+python: The way to write a slide control yourself

Source: Internet
Author: User

#调用方式
Roll_ele ("ID", "ele_id", "7", "Up", 3) #将控件分为7格, swipe up 3 from the bottom-down second grid
#滑动控件的方法
def
Roll_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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.