• 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就是要需要尝试才熟练。

  • 相关阅读:
    codeforces 589G G. Hiring(树状数组+二分)
    树状数组的小总结
    virtualenv
    Redis备份与恢复
    Linux 网站相关
    MySQL文章参考
    动态执行表不可访问,本会话的自动统计被禁止 。 在执行菜单里你可以禁止统计,或在v$session,v$sesstat 和 v$statname 表里获得select权限
    app已损坏,打不开。你应该将它移到废纸篓
    macos系统用virtualbox安装Linux系统无法设
    Hadoop 分布式部署HDFS-hadoop用户部署
  • 原文地址:https://www.cnblogs.com/nemolmt/p/6212767.html
Copyright © 2020-2023  润新知