1. 程式人生 > 實用技巧 >appium 觸控操作

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