appium 触摸操作

1、导入模块: from appium.webdriver.common.touch_action import TouchAction

2、单击控件:tap(self ,element=None, x = None, y = None, count=1),count表示单击的次数

3、长按控件: long_press(self, el=None,x = None, y = None, duration=1000),duration表示持续的时间,单位毫秒

from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

caps = {}
caps["deviceName"] = "HWJSN-HW"
caps["automationName"] = "appium"
caps["platformVersion"] = "10"
caps["platformName"] = "Android"
caps["appPackage"] = "com.youdao.dict"
caps["appActivity"] = ".activity.MainActivity"
caps["ensureWebviewsHavePages"] = True

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

#弹窗处理  
try:
    loc = ("xpath", "//*[@text='始终允许']")
    el = WebDriverWait(driver, 5, 0.5).until(EC.presence_of_element_located(loc))
    TouchAction(driver).tap(el).perform()
except:
    pass

 

posted @ 2020-09-09 22:34  jerrygogo  阅读(223)  评论(0编辑  收藏  举报