仅供自己参考
udid获取:adb devices
滑动1:TouchAction(self.driver).press(x=1000,y=1000).move_to(x=0,y=100).wait(1000).release().perform()
'''move_to后面的坐标是改变量的坐标'''
滑动2:x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
self.driver.swipe(0.5*x,0.8*y,0.5*x,0.3*y,1000)
长按:TouchAction(self.driver).long_press(元素,时间).release().perform()
安卓的相同类的元素提取1:self.driver.find.element_by_android_uiautomator('new UiSelector().textContains("名字")')#后面的方法也可以是text(),textStartWith(),textMatches()
安卓的相同类的元素提取2:self.driver.find.elements_by_class_name("类名")[3]
'''中括号内的数字需要手动打印看一下起始排序,暂未发现更好的方法'''
安卓相同类元素的提取3:self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
'''返回的是可点击按钮的一串数组'''
导入的内容:from appium.webdriver.common.touch_action import TouchAction
from appium import webdriver
import time
import unittest
获取屏幕的尺寸后滑动: x1 = self.driver.get_window_size()['width']
y1 = self.driver.get_window_size()['height']
self.driver.swipe(0.5*x1,0.8*y1,0.5*x1,0.3*y1,1000)
输入中文字符串:caps["unicodeKeyboard"]=True 使用unicodeKeyboard的编码方式来发送字符串
caps["resetKeyboard"]=True将键盘给隐藏起来
点击某个按钮:self.driver.tap(([893,231],[132,432]),1000)
action.press(312,123).wait(4000).release().perform()
获取元素的属性:.get_attribute("className") .get_attribute("clickable") .get_attribute("resourceId") .get_attribute("text")
获取当前页面的activity:self.driver.current_activity
跳过当前加载页面:self.driver.wait_activity("",20)#20为超时时间
置于后台运行: driver.background_app(5)
安装app:driver.install_app(app_path)
页面返回:print(self.driver.current_context)
print(self.driver.contexts)
print(self.driver.context)
分别为
NATIVE_APP
['NATIVE_APP']
NATIVE_APP
webview上的根据content-desc定位:self.driver.find_element_by_accessibility_id("")
多点触控:action1=Touchaction(self.driver).tap(231,31)
action2=Touchaction(self.driver).tap(321,54)
MultiAction.add(action1).add(action2).tap
锁屏:self.driver.lock(5)
置于后台:self.driver.background_app(-1) #-1表示持续的置于后台,
ios的定位方法self.driver.find_elements_by_ios_predicate("type==XXXX and label contains 'XXX' and enabled=true and name between {1,4} and name in {1asd,dsa} and label like '中华?共*国’label matches "正则表达式")