TouchAction
Touch Action contains a series of operations such as press, long press, click, move, suspended.
Use TochAction need to import the corresponding module
from appium.webdriver.common.touch_action import TouchAction
Press
Use to press () method, the phone screen by pressing a finger to a location, press may be an element, you can also receive screen coordinates (x, y).
press(self, el=None, x=None, y=None)
TouchAction(driver).press(x=200,y=200).release().perform()
Press
Using the longpress () method, similar to the press, a plurality of delay time duration (in milliseconds) than the press
long_press(self, el=None, x=None, y=None, duration=1000)
TouchAction(driver).long_press(x=200,y=200,duration=1000).release().perform()
Click on
Using the tap () method, a click operation may be performed on a control element or usage reference press ().
tap(self, element=None, x=None, y=None, count=1)
mobile
Using the move_to () method, a pointer from the point to the specified elements or points.
move_to(self, el=None, x=None, y=None)
note:
Moves to the destination position is sometimes considered an absolute coordinate point, sometimes offset based on a coordinate point in front , this should be practiced in conjunction with specific App.
time out
Methods: Wait ()
the wait (Self, MS = 0), to suspend execution of the script, in milliseconds.
freed
Method release () to cancel the closing of the pointer on the screen.
release(self)
carried out
Operation perform () command sent to the server performs an operation.
perform(self)
TouchAction real - squares slide operation
Case Scenario:
Enter the mobile phone comes with the app housekeeper, there are applications have been encrypted, you need to enter the squared unlock encrypted permissions settings for other applications.
Code:
# -*- coding: utf-8 -*-# from appium.webdriver.common.touch_action import TouchAction from appium import webdriver from selenium.common.exceptions import NoSuchElementException import time desired_caps = { "platformName": "Android", "platformVersion": "5.1", "deviceName": "U4KF9HSK99999999", "appPackage": "com.coloros.safecenter", "appActivity": "com.coloros.safecenter.MainActivity", "unicodeKeyboard":True, "resetKeyboard":True, "noReset": True #"ANDROID_UIAUTOMATOR":"Uiautomator2", # "chromeOptions": {"androidProcess": "com.wondershare.drfone"} } Driver = webdriver.Remote ( " HTTP: // localhost: 4723 / WD / Hub " , desired_caps) driver.implicitly_wait ( . 5 ) driver.find_element_by_id ( " com.coloros.safecenter: ID / image_permission " ) .click () Time. SLEEP ( 2 ) driver.find_element_by_xpath ( " // * [@ text = 'XXXX'] " ) .click () the time.sleep ( 2 ) # begins to slide to unlock, this app is based on the coordinates of the offset calculation TouchAction ( Driver) .press (X = 270, Y = 791) .wait (2000 ). \ move_to (X = 270, Y = 0) .wait (1000 ). \ move_to (X = 270, Y = 0) .wait ( 1000 ). \ move_to(x=0,y=270).wait(1000).release().perform() try: driver.find_element_by_class_name("android.widget.Switch") except NoSuchElementException: print("解锁失败!") else: print("解锁成功!")
Reference reprint: https: //www.cnblogs.com/xuzhongtao/p/9723222.html