Appium Android 控件的交互方式

目录

原生APP

一、SeekBar滑动条

1、点击

2、滑动

3、触控

二、Switch开关

三、Alert消息框

四、Spinner下拉列表

混合型APP-----内嵌H5(html5)页面的APP

五、EditText文本框

六、Webview网页


原生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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值