continuous sliding appium--

TouchAction

Prior to said sliding swip, that is sliding between two points, such as on slippery, slippery left. But the actual work will encounter some complex scenarios, such as squared sliding wait, this time we should use TouchAction, TouchAction contains a series of operations such as press, long press, click, move, pause, use TouchAction need to import the corresponding module

from appium.webdriver.common.touch_action import TouchAction

Press

Methods: press () to start a pressing element or coordinate point (x, y), by pressing a finger to a location of the phone screen, press () can also receive the screen coordinates (x, y)

press(self,el=None,x=None,y=None)

TouchAction(driver).press(x=0,y=300)

TouchAction(driver).press(x=0,y=308).release().perform()

In addition Press () method, this embodiment further uses new methods other two outside.

  • release action () to cancel the end of the pointer on the screen.
  • The Perform Operation () executing operation commands sent to the server

Press

Methods: longPress ()

Starts pressing element or a coordinate point (x, y). Compared press () method, longPress () one more to the Senate, since the press, and must have time to press it. duration in milliseconds. 1000 represented by one second. Press and its usage () in the same manner.

long_press(self,el=None,x=None,y=None,duration=1000)

Click on

Methods: tap ()

Click to perform operations on one element or control. Usage reference press ().

tap(self,el=None,x=None,y=None,count=1)

mobile

move_to () the pointer from a point to the point specified element or

move_to(self,el=None,x=None,y=None)

Note: sometimes moved to the target position calculated absolute path, sometimes an offset based on a coordinate point in front of, to be practiced in conjunction with a particular app

time out

Wait()

wait(self,ms=0)

In ms


freed

Method release () pointer on the end of the action or cancel the screen

release(self)

carried out

Operation perform () executing operation commands sent to the server

perform(self)

Real

Objective: to complete the slide following the pattern

 1 from appium.webdriver.common.touch_action import TouchAction
 2 from appium import webdriver
 3 
 4 desired_caps = {}
 5 desired_caps['platformName'] = 'Android'
 6 desired_caps['deviceName'] = '127.0.0.1:62001'
 7 desired_caps['platforVersion'] = '5.1.1'
 8 desired_caps['app'] = r'F:\xxx.apk'  # 安装app
 9 desired_caps['appPackage'] = 'com.xxx'
10 desired_caps['appActivity'] = 'com.bizxxx'
11 
12 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
13 
14 
15 def get_size():
16     x = driver.get_window_size()['width']
17     y = driver.get_window_size()['height']
18     return x, y
19 
20 # 向左滑动
21 def swipeleft():
22     l = get_size()
23     x1 = int(l[0] * 0.9)
24     y1 = int(l[1] * 0.5)
25     x2 = int(l[0] * 0.1)
26     driver.swipe(x1, y1, x2, y1, 1000)
27 
28 # 向上滑动
29 def swipeUp():
30     l = get_size()
31     x1 = int(l[0] * 0.5)
32     y1 = int(l[1] * 0.95)
33     y2 = int(l[1] * 0.35)
34     driver.swipe(x1, y1, x1, y2, 1000)
35 
36 
37 for i in range(2):
38     TouchAction(driver).press(x=262, y=385).wait(2000) \
39         .move_to(x=451, y=388).wait(1000) \
40         .move_to(x=650, y=589).wait(1000) \
41         .move_to(x=649, y=785).wait(1000) \
42         .release().perform()

Code explanation:

Line 28 performs the sliding operation, the first press point Press Wait 2 seconds, line 39 represents movement to the second point, wait 1 second, line 40 represents the move to the third point, wait 1s, 41 represents a row, moved to a fourth point, wait 1s, line 42 release () indicates continuous release slide operation, perform () represents a series of operations performed to the service side of the front

Guess you like

Origin www.cnblogs.com/zouzou-busy/p/11406019.html