Appium+python Automation 24-Slide method package (swipe) "reprint"

Source: Internet
Author: User
Tags appium

Swipe Introduction

1. View source syntax, start and end four coordinate parameters, duration is the duration of the slide screen, the shorter the faster. The default is None, the general setting of 500-1000 milliseconds is more appropriate.

swipe(self, start_x, start_y, end_x, end_y, duration=None)     Swipe from one point to another point, for an optional duration.    从一个点滑动到另外一个点,duration是持续时间            :Args:    - start_x - 开始滑动的x坐标    - start_y - 开始滑动的y坐标    - end_x - 结束点x坐标    - end_y - 结束点y坐标    - duration - 持续时间,单位毫秒        :Usage: driver.swipe(100, 100, 100, 400)

2. Mobile phone from the upper left corner of the 0, the horizontal is the x axis, vertical is the y axis

Get coordinates

1. Because each phone screen resolution is not the same, so the same element in different mobile phone coordinates are not the same, sliding when the coordinates can not be written dead. You can get the width and height of the screen first, and then calculate by proportion.

# Coding:utf-8From AppiumImport Webdriverdesired_caps= {' PlatformName ':' Android ',' DeviceName ':' 30d4e606 ',' Platformversion ':' 4.4.2 ',# APK Package Name' Apppackage ': ' Com.taobao.taobao ', # APK launcheractivity  ' appactivity ':  ' com.taobao.tao.welcome.Welcome '}driver = webdriver. Remote ( ' Http://127.0.0.1:4723/wd/hub ', desired_caps) # get screen sizesize = driver.get_window_size () print (size) # screen width widthprint (size[  ' width ') # screen height widthprint (size[            

2. Operation Result:

{u‘width‘: 720, u‘height‘: 1280}7201280
Package Slide method

1. The upper and lower left and right four kinds of commonly used sliding method package, so that you want to slide the screen when you can directly call the
Parameter 1:driver
Parameter 2:t is the duration
Parameter 3: Number of slides

2. Case reference

# Coding:utf-8From AppiumImport WebdriverFrom timeImport Sleepdesired_caps= {' PlatformName ':' Android ',' DeviceName ':' 30d4e606 ',' Platformversion ':' 4.4.2 ',# APK Package Name' Apppackage ':' Com.taobao.taobao ',# APK for Launcheractivity' Appactivity ':' Com.taobao.tao.welcome.Welcome '}driver= Webdriver. Remote (' Http://127.0.0.1:4723/wd/hub ', desired_caps)Def Swipeup(Driver, T=500N=1):' Swipe up on the screen ' L= Driver.get_window_size () x1= l[' Width ']*0.5# x-coordinate Y1= l[' Height ']*0.75# start y-coordinate y2= l[' Height ']*0.25# end point Y coordinateFor IInchRange (N): Driver.swipe (x1, y1, x1, y2, t)Def Swipedown(Driver, T=500N=1):"' swipe down on the screen ' L= Driver.get_window_size () x1= l[' Width ']*0.5# x-coordinate Y1= l[' Height ']*0.25# start y-coordinate y2= l[' Height ']*0.75# end point Y coordinateFor IInchRange (N): Driver.swipe (x1, y1, x1, y2,t)Def Swipleft(Driver, T=500N=1):"Swipe left screen" ' L= Driver.get_window_size () x1= l[' Width ']*0.75 y1= l[' Height ']*0.5 x2= l[' Width ']*0.05For IInchRange (N): Driver.swipe (x1, y1, x2, y1, T)Def Swipright(Driver, T=500N=1):"' swipe right on screen ' L= Driver.get_window_size () x1= l[' Width ']*0.05 y1 = l[ ' height '] * 0.5 x2 = l[ ' width ' ] * 0.75 for I in range (n): Driver.swipe (x1, y1, x2, y1, T) if __name__ == " __main __ ": print (driver.get_window_size ()) Sleep (5) Swipleft (Driver, n =2) sleep (2) swipright (driver, N= 2)               

Appium+python Automation 24-Slide method Encapsulation (swipe) "reprint"

Related Article

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.