Appium使用

初始化
# Android environment


from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.1'
desired_caps['automationName'] = 'uiautomator2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')

self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 查找元素
el = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Animation")')
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')

el = self.driver.find_element_by_android_viewtag('a tag name')
els = self.driver.find_elements_by_android_viewtag('a tag name')


# 点击
tap()
click()

# 动作链
el = self.driver.find_element_by_accessibility_id('Animation')
action = TouchAction(self.driver)
action.tap(el).perform()


# 多动作
els = self.driver.find_elements_by_class_name('listView')
a1 = TouchAction()
a1.press(els[0])
.move_to(x=10, y=0).move_to(x=10, y=-75).move_to(x=10, y=-600).release()

a2 = TouchAction()
a2.press(els[1])
.move_to(x=10, y=10).move_to(x=10, y=-300).move_to(x=10, y=-600).release()

ma = MultiAction(self.driver, els[0])
ma.add(a1, a2)
ma.perform();


# 拖动
driver.swipe

FLICK_START_X = 300
FLICK_START_Y = 300
FLICK_DISTANCE = 700

def scroll(self):
while True:
self.driver.swipe(FLICK_START_X, FLICK_START_Y + FLICK_DISTANCE, FLICK_START_X, FLICK_START_Y)
sleep(2)

原文地址:https://www.cnblogs.com/kenD/p/12449948.html