no.5-Swipe and Tap

Source: Internet
Author: User
Tags appium

For Android devices, touch screen class operation is the most commonly used, such as: Click, long Press, drag, slide screen, zoom and so on, appium to these kinds of operations have provided API support, and the classification is quite thin. Some have read the introduction, also still did not understand, today take them out to sacrifice a bit.

Good ~ sir, vegetables come!!!

1.swipe (self, start_x, start_y, end_x, end_y, Duration=none)

Swipe from one point to another point, for a optional duration.
: Args:
-Start_x-x-coordinate at which to start
-Start_y-y-coordinate at which to start
-End_x-x-coordinate at which to stop
-End_y-y-coordinate at which to stop
-duration-(optional) time to take the swipe, in Ms.
: Usage:
Driver.swipe (100, 100, 100, 400)

The approximate meaning of this API is: sliding through the coordinates, the first two are the starting XY coordinates, the last two are the end of the XY coordinate, there is a usable time parameter

Before starting the experiment, turn on the phone's coordinates and the slide track, and the way to open the millet is this:

1. ' Set ', ' about mobile '-' MIUI version ', aim at ' MIUI version ' Mad Point 6 times, open ' developer mode '

2. ' Settings ', ' Other advanced Settings ', ' Developer Options ', ' Show Touch action ' and ' pointer position ', turn these two items on.

3. Then just

The xy coordinate displayed at the top, and the ' circle ' in the middle is the sliding trajectory of the display.

Once this is done, look at the interface used to experiment:

Swipe up and down to see the article, this is a very common interface, use ' swipe ' to try sliding.

Execute code:

Driver.swipe (800,1600,800,800,3000)

Results :

Can see a straight slide mark, the interface does respond to sliding

Minor problems with coordinates:

1. The time is in milliseconds, which means that you want 1 seconds, you need to write 1000.

2. If the setting time is too short, it is likely that the slide operation has been performed, but no sliding reaction, so the time is best set a little longer, recommended 3000.

3. The proposed coordinates do not start from 0 and are likely to be scratched (manually starting from 0 and not responding).

4. When you enter an xy coordinate that is greater than 1, it is processed in pixels. When the xy coordinate of the input is less than 1, it is processed according to the percentage of the current pixel, and 0.5 is 50%,x=0.5,y=0.5 so this coordinate is the center of the screen.

2.flick (self, start_x, start_y, end_x, end_y)

Flick from one point to another point.
: Args:
-Start_x-x-coordinate at which to start
-Start_y-y-coordinate at which to start
-End_x-x-coordinate at which to stop
-End_y-y-coordinate at which to stop
: Usage:
Driver.flick (100, 100, 100, 400)

The approximate meaning of this API: swipe from one point to another

Looks like swipe, just a few optional time, I search for a saying is fast sliding ~ with just the page to try water.

Code execution: Driver.flick (800,1600,800,800)

results : The coordinates provided to an interactions operation is invalid.

' Nani? ' Give me an error ~ said I provided the coordinates are invalid, this set of coordinates ' swipe ' clearly can be used, change the coordinates of the horizontal look.

Code execution: Driver.flick (1000,500,100,500)

result : The coordinates provided to an interactions operation is invalid.

··················· or not ~ ~ doesn't seem to be the problem, I use the coordinates in the example to try.

Code execution: Driver.flick (100,100,100,400)

Results :

Look at this riddle-like trajectory line ~ can confirm that the same set of coordinates ' flick ' execution of the trajectory is the same, it is in accordance with a law I do not understand, foreign aunts are following the helpless ...

3.drag_and_drop (self, origin_el, Destination_el)

Drag The origin element to the destination element
: Args:
-Originel-the element to drag
-destinationel-the element to drag to

The approximate meaning of this API: Drag from element A to element b

I still like this sliding way, from one element to another, compared to the coordinates of ' swipe ', ' Drag_and_drop ' feels more controllable, because the elements are constant for different screen sizes.

Execute code:

A = Driver.find_element_by_name (' 7 ')
b = Driver.find_element_by_name (' 123 ')
Driver.drag_and_drop (A, B)

Results :

After dragging from ' 7 ' to ' 123 ', it is this way, obviously feel the "drag" two words when looking at this process, I feel the force outside the screen.

4.click (self)

Clicks the Element

The approximate meaning of this API: click on the Element

This is a very common API, the usage is "locate. Click ()", for example: Driver.find_element_by_name (' 123 '). Click ()

5.press (self, el=none, X=none, Y=none)

Begin a chain with a press down action @ a particular element or point

The approximate meaning of this API: click on the element or point (coordinates).

Let's take a look at the simple logic to manipulate the interface

When you click "Other", the window with the added label will pop up.

Execute code:

From appium.webdriver.common.touch_action import touchaction

b = Driver.find_element_by_xpath (a)
Touchaction (Driver). Press (b). Release (). Perform ()

Results :

Clicked on to the

Click on the habit of clicking, this writing is too troublesome, do an extension of knowledge it.

6.tap (self, positions, Duration=none)

Taps on the particular place and up to five fingers, holding for a
Certain time


: Args:
-Positions-an array of tuples representing the X/y coordinates of
The fingers to tap. Length can to five.
-duration-(optional) length of time to tap, in MS

: Usage:
Driver.tap ([(100, 20), (100, 60), (100, 100)], 500)

The approximate meaning of this API: 5-point touch, to maintain a certain amount of time

Execute code:

Driver.tap ([(0.7,0.8)],10000)

Results :

Effective, use a percentage coordinate to point. Say up to five touch, I'm trying to add a few.

Execute code:

Driver.tap ([(0.7,0.8), (0.5,0.6), (0.4,0.3), (0.2,0.6), (0.9,0.9)],10000)

results : No response, even the track shows are gone, try the normal coordinates.

Execute code:

Driver.tap ([(300,80), (300,90), (300,100), (300,110), (300,120)],10000)

Results :

In a small corner, a five-point touch track, but did not perform the 10-second time I set.

Well, it looks like this is the pit.

1.tap when performing percent coordinates, you can only set a set of XY, multiple sets of XY time does not work.

2. Multiple sets of XY can only use actual coordinates, and the set time is not valid.

7.long_press (self, el=none, X=none, Y=none, duration=1000)

Begin a chain with a press off that lasts ' duration ' milliseconds

The approximate meaning of this API is: by long pressing the element or coordinate


This usage is similar to the press, the difference is a time setting, the default is 1 seconds.

Execute code:

From appium.webdriver.common.touch_action import touchaction

b = Driver.find_element_by_xpath (a)
Touchaction (Driver). long_press (b,duration=2000). Release (). Perform ()

result : No results were posted.

Again, the API is smelly and long, and feels like a hassle to write, but it's critical that it can be long-pressed by element positioning.

Here are a few alternative ' long-press ' scenarios that you can consider:

1. ' Tap ' is set for 2 seconds or longer, and can be long-pressed. Tap ([500,500],2000)

The start and end coordinates of the 2.swipe setting are consistent, with a sliding time of 2 seconds, and a long press can be achieved. Swipe (100,200,100,200,2000)

The food is all ~

no.5-Swipe and Tap

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.