Fork me on GitHub

selendroid inspector xpth元素定位记录

android自动化测试元素定位,目前发现appium官方的uiautomatorviewer一般的元素定位还行,但好多都找不到。

这个时候,可以考虑selendroid的inspector

官网:http://selendroid.io/inspector.html

使用 E:\APP>java -jar selendroid-standalone-0.17.0-with-dependencies.jar -app app-debug_3.1.3.904.apk

类似的模式打开selendroid纯服务器。

然后是python客户端代码:

#coding=utf-8
'''@author: lhy.yh@qq.com
'''
import unittest
from selenium import webdriver


class FindElementTest(unittest.TestCase):

def setUp(self):
desired_capabilities = {'aut': 'com.tenda.router.app:3.1.3.904'}


#desired_capabilities = {'aut': 'io.selendroid.testapp:0.17.0'}
self.driver = webdriver.Remote(
desired_capabilities=desired_capabilities
)
self.driver.implicitly_wait(30)

def test_find_element_by_id(self):
self.driver.get('and-activity://com.tenda.router.app.activity.Anew.Splash.SplashActivity')

def tearDown(self):
self.driver.quit()

if __name__ == '__main__':
unittest.main()

如果大家不知道:

desired_capabilities = {'aut': 'com.tenda.router.app:3.1.3.904'}

里面的aut参数哪来的,那LZ再啰嗦一下:

1、打开http://localhost:4444/wd/hub/status

2、好了自己找想要的内容appId

3、要想正常运行APP,建议先到安卓系统APP应用卸载的地方,1、先卸载待测软件、2、再卸载selendroid名称的应用

{"value":{"os":{"name":"Windows 7","arch":"x86","version":"6.1"},"build":{"browserName":"selendroid","version":"0.17.0"},"supportedDevices":[{"emulator":false,"screenSize":"(1440, 2560)","serial":"LGD857cfd6ea69","platformVersion":"21","model":"LG-D857","apiTargetType":"google"}],"supportedApps":[{"mainActivity":"io.selendroid.testapp.HomeScreenActivity","appId":"io.selendroid.testapp:0.17.0","basePackage":"io.selendroid.testapp"},{"mainActivity":"io.selendroid.androiddriver.WebViewActivity","appId":"io.selendroid.androiddriver:0.17.0","basePackage":"io.selendroid.androiddriver"}]},"status":0}

特别留意需要使用debug模式,在APP初始化之后,取个断点就可以了。(前提是IDE需要支持DEBUG,例如LZ使用的是wing ide)

然后就打开APP 进入你需要定位的界面:

例如 LZ的:

 

LZ是想定位到WIFI开始时段、关闭时段需要输入的 4个时间值。例如图中深黑的数字,是一个textfield是可以输入的。

使用XPATH表达式:dr.find_element(:xpath,'//ScrollView/LinearLayout/LinearLayout/RelativeLayout/LinearLayout/NumberPicker\[1\]/CustomEditText').text

即可定位到第一个 17

以此类推

31

dr.find_element(:xpath,'//ScrollView/LinearLayout/LinearLayout/RelativeLayout/LinearLayout/NumberPicker\[3\]/CustomEditText').text

23

dr.find_element(:xpath,'//ScrollView/LinearLayout/LinearLayout/RelativeLayout/LinearLayout/NumberPicker\[4\]/CustomEditText').text

43

dr.find_element(:xpath,'//ScrollView/LinearLayout/LinearLayout/RelativeLayout/LinearLayout/NumberPicker\[6\]/CustomEditText').text

 

关于XPATH的语法就不多讲,XPATH就是要需要尝试才熟练。

 

posted @ 2016-12-22 20:39  流氓兔Nemo  阅读(914)  评论(0编辑  收藏  举报