目录
原生APP
一、SeekBar滑动条
1、点击
相关方法:
click()点击控件
driver.tap()点击坐标
滑动条0-100,代码演示点击60处。
from appium import webdriver
from time import sleep
import unittest
class AppTests(unittest.TestCase):
def setUp(self) -> None:
desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = r"D:\AppPackage\TestApks\AndroidUI.apk"
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
self.driver.implicitly_wait(10)
def tearDown(self) -> None:
sleep(2)
self.driver.quit()
def test_1(self):
driver=self.driver
el=driver.find_element_by_android_uiautomator('.resourceId("com.android.androidui:id/seekBar1")')
# 点击滑动条是点击滑动条的中心位置(50处)
el.click()
#大小
print('size:',el.size)
# 滑动条左上角的坐标
print('location:',el.location)
x=el.location['x']+60*el.size['width']/100
y=el.location['y']+el.size['height']/2
# 指定坐标(60处),模拟手指点击控件
# tap()第一个参数是坐标;第二个参数是点击时间,单位毫秒,默认短按。
driver.tap([(x,y)])
# 可设置最多五个手指同时点击屏幕,直接在列表加坐标。
driver.tap([(x, y),(100,200)])
# 可设置长按,给第二个参数传参。
driver.tap([(x, y)],3000)
执行结果:
size: {'height': 59, 'width': 1280}
location: {'x': 0, 'y': 587}
2、滑动
相关方法:
driver.swipe()可设滑动时间,慢滑比快滑准确。
driver.flick()不可设滑动时间,飞快一滑,误差最差。
滑动条0-100,代码演示从0滑动到60处。
from appium import webdriver
from time import sleep
import unittest
class AppTests(unittest.TestCase):
def setUp(self) -> None:
desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = r"D:\AppPackage\TestApks\AndroidUI.apk"
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
self.driver.implicitly_wait(10)
def tearDown(self) -> None:
sleep(2)
self.driver.quit()
def test_1(self):
driver=self.driver
el=driver.find_element_by_android_uiautomator('.resourceId("com.android.androidui:id/seekBar1")')
x=el.location['x']+60*el.size['width']/100
y=el.location['y']+el.size['height']/2
# dura