博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
appium(2)--元素定位篇
阅读量:4068 次
发布时间:2019-05-25

本文共 2702 字,大约阅读时间需要 9 分钟。

from appium import webdriverimport timeserver = 'http://127.0.0.1:4723/wd/hub'

连接设备参数

desired_caps = {"deviceName": "d9d26a8f","platformVersion": "9","platformName": "Android","appPackage": "com.tencent.mm","appActivity": "com.tencent.mm.ui.LauncherUI","unicodeKeyboard": "True","resetKeyboard": "True","noReset": "True"}

远程遥控

b = webdriver.Remote(server, desired_caps)

元素定位

android_uiautomator

1.android_uiautomator text定位

1.1uiautomator tex精确定位
ele = b.find_element_by_android_uiautomator(‘new UiSelector().text(“通讯录”)’)
ele.click()
1.2uiautomator textContains模糊定位
ele = b.find_element_by_android_uiautomator(‘new UiSelector().textContains(“通讯”)’)
ele.click()
1.3uiautomator textStartsWith文本开头定位
ele = b.find_element_by_android_uiautomator(‘new UiSelector().textStartsWith(“通讯”)’)
ele.click()
1.4uiautomator textMatches正则表达式定位
ele = b.find_element_by_android_uiautomator(‘new UiSelector().textMatches(“通讯.”)’)
ele.click()

  1. android_uiautomator resourceId定位,resourceIdMatches定位

    ele1 = b.find_element_by_android_uiautomator(‘new UiSelector().resourceId(“com.tencent.mm:id/cn1”)’)
    ele1.click()

  2. android_uiautomator className

    class属性一般不唯一,多半用在复数定位,className复数定位–find_elements
    ele_list = b.find_elements_by_android_uiautomator(‘new UiSelector().className(“android.widget.ImageView”)’)
    print(ele_list)
    ele_list[0].click()

  3. android_uiautomator多属性组合定位,一般组合用id,class,text这三个属性

    id+class 属性组合
    id_class = ‘resourceId(“com.tencent.mm:id/f8y”).className(“android.widget.ImageView”)’
    b.find_element_by_android_uiautomator(id_class).click()
    id+text 属性组合
    id_text = ‘resourceId(“com.tencent.mm:id/cns”).text(“通讯录”)’
    b.find_element_by_android_uiautomator(id_text).click()
    android_uiautomator description定位
    ele = b.find_element_by_android_uiautomator(‘new UiSelector().description(“更多功能按钮,已折叠”)’)
    ele.click()
    descriptionStartsWith
    b.find_element_by_android_uiautomator(‘new UiSelector().descriptionStartsWith(“更多功能”)’)
    descriptionMatches
    b.find_element_by_android_uiautomator(‘new UiSelector().descriptionMatches(".*折叠$")’).click()

selenium

1.xpath定位

ele2 = b.find_element_by_xpath(’//*[@resource-id=“com.tencent.mm:id/bhn” and @text=“搜索”]’)
ele2.click()
ele2.send_keys(“缘来是你阿”)
2. id定位
ele3 = b.find_element_by_id(“com.tencent.mm:id/gbv”)
ele3.click()

元素关系定位

  1. 父子定位childSelector
    son = ‘resourceId(“com.tencent.mm:id/g73”).childSelector(resourceId(“com.tencent.mm:id/giv”))’
    ele = b.find_element_by_android_uiautomator(son)
    ele.click()
  2. 兄弟定位fromParent
    brother = ‘resourceId(“com.tencent.mm:id/g73”).childSelector(resourceId(“com.tencent.mm:id/giv”)).fromParent(className(“android.widget.LinearLayout”))’
    b.find_element_by_android_uiautomator(brother).click()

description

b.find_element_by_accessibility_id(“更多功能按钮,已折叠”).click()

转载地址:http://atmji.baihongyu.com/

你可能感兴趣的文章
db sql montior
查看>>
Unix + SCO UnixWare
查看>>
db db2 books
查看>>
read humor_campus
查看>>
my read_soft
查看>>
my pdfs
查看>>
framework Schedule Quartz
查看>>
IBM WebSphere Commerce Analyzer
查看>>
Unix + OS IBM Aix System Director
查看>>
Unix + OS IBM Aix FTP / wu-ftp / proftp
查看>>
framework apache commons
查看>>
my read work
查看>>
blancerServer IBM WebSphere Edge Server 6.1
查看>>
db db2 base / instance database tablespace container
查看>>
my read _job
查看>>
hd disk / disk raid / disk io / iops / iostat / iowait / iotop / iometer
查看>>
project ASP.NET
查看>>
db db2_monitorTool IBM Rational Performace Tester
查看>>
OS + Unix Aix telnet
查看>>
IBM Lotus
查看>>