APP元素定位操作:
name | value |
---|---|
id属性值 | id属性值 |
class | class属性值 |
xpath | xpath表达式 |
前置代码:
from appium import webdriver
# server 启动参数
desired_caps = {}
# 设备信息
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '192.168.56.101:5555'
# app的信息
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
# 声明我们的driver对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
通过xpath定位:
*** android端xptah常用属性定位:
1. id ://[contains(@resource-id,‘com.android.settings:id/search’)]
2. class ://[contains(@class,‘android.widget.ImageButton’)]
3. text ://*[contains(@text,‘WLA’)]
*** 模糊定位 contains(@key,value): value可以是部分值
另一种方式:find_element_by_xpath("//*[(@text=‘继续’)]")