There is a delay in updating articles on this site, if you want to see articles about Python + Appium, please follow me over to Testhome. Testerhome.com/topics/2780…
The screen coordinates of the mobile phone are shown as follows: the upper left corner of the mobile phone is (0,0), the horizontal axis is x axis, and the vertical axis is y axis
Swipe (x1, y1, x2, y2, t) : (x1, y1) is the coordinates of the starting point of sliding, (x2, y2) is the coordinates of the end point of sliding, and t is the sliding time, in ms
Get the screen size of the mobile phone, because the screen resolution of each mobile phone is different, so the coordinates of the same element on different mobile phones are different, the sliding coordinates can not be written dead, can be calculated by the ratio of screen width and height
1. Slide up: the main operation is B→A in the figure, X-axis coordinates remain unchanged, and Y-axis coordinates change from large to small, from 75% of the longitudinal length of the screen to 25%
2. Slide down: The main operation is A→B in the figure, X-axis coordinates remain unchanged, and Y-axis coordinates change from small to large, from 25% of the longitudinal length of the screen to 75%
3. Left slide: the main operation is D→C in the figure, Y-axis coordinates remain unchanged, and the left side of X-axis changes from large to small, from 75% of the horizontal length of the screen to 25%
4. Right slide: the main operation is C→D in the figure, Y-axis coordinates remain unchanged, and the left side of X-axis changes from small to large, from 25% of the horizontal length of the screen to 75%
The script for sliding operation is as follows:
# Slide operation
from appium import webdriver
class Slide:
driver: webdriver = None
Get the screen size
def get_screen_size(self) :
return self.driver.get_window_size(self)
# on the slide
def swipe_up(self, t) :
screen_size = self.get_screen_size()
x1 = screen_size['width'] * 0.5
y1 = screen_size['height'] * 0.75
y2 = screen_size['height'] * 0.25
self.driver.swipe(x1, y1, x1, y2, t)
Decline in #
def swipe_down(self, t) :
screen_size = self.get_screen_size()
x1 = screen_size['width'] * 0.5
y1 = screen_size['height'] * 0.25
y2 = screen_size['height'] * 0.75
self.driver.swipe(x1, y1, x1, y2, t)
Slide # left
def swipe_left(self, t) :
screen_size = self.get_screen_size()
x1 = screen_size['width'] * 0.75
y1 = screen_size['height'] * 0.5
x2 = screen_size['width'] * 0.25
self.driver.swipe(x1, y1, x2, y1, t)
# right
def swipe_right(self, t) :
screen_size = self.get_screen_size()
x1 = screen_size['width'] * 0.25
y1 = screen_size['height'] * 0.5
x2 = screen_size['width'] * 0.75
self.driver.swipe(x1, y1, x2, y1, t)
Copy the code