Appium+python Automation 48-long Press (long_press)

Source: Internet
Author: User
Tags appium

Long-press operation is often encountered in the scene, through the driver can directly call up the Long_press_keycode method, but this method is to long press a button on the phone, such as long press the Power key, long press the home button.
Long pressing an element or long pressing a point on the screen requires the long_press operation provided in the touchaction.

Locating the ListView

1. First look at which scenes are the ListView

2. The ID of each row in the ListView is the same, using the list as mentioned above to remove the label.

3. Positioning reference

# 定位聊天记录列表,选第一个长按el = driver.find_elements_by_id("com.tencent.mm:id/apv")[0] 
Long Press Long_press

1. Long-press operation can be done using the Long_press method in the Touchaction class mentioned above

def long_press(self, el=None, x=None, y=None, duration=1000): 长按操作,可以传定位的元素对象,也可以传坐标 el 是定位元素的对象 x,y是传坐标 duration是按住的持续时间,默认1000,单位是毫秒 

2. Implementation methods

# 长按TouchAction(driver).long_press(el).perform()
Reference Code
#Coding:utf-8 fromAppiumImportWebdriver fromAppium.webdriver.common.touch_actionImporttouchactionImportTimedesired_caps= {                'PlatformName':'Android',                'platformversion':'7.0',                'devicename':'a5rnw18316011440',                'Apppackage':'com.tencent.mm',                'appactivity':'. UI. Launcherui',                'Automationname':'Uiautomator2',                #' Unicodekeyboard ': True,                #' Resetkeyboard ': True,                'NoReset': True,#' chromeoptions ': {' androidprocess ': ' Com.tencent.mm:tools '}}driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps) driver.implicitly_wait (10)#Locate the Chat History list and select the first long pressEl = driver.find_elements_by_id ("COM.TENCENT.MM:ID/APV") [0]#Long Presstouchaction (Driver). long_press (EL). Perform () Time.sleep (3)#Locate the option box ' Delete this chat 'Driver.find_element_by_xpath ("//*[@text = ' Delete this chat ']"). Click () time.sleep (3)#Locate the option box ' Cancel 'DRIVER.FIND_ELEMENT_BY_ID ("Com.tencent.mm:id/alk"). Click ()

Appium+python Automation 48-long Press (long_press)

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.