appium+python自动化31-android_uiautomator定位,,前言appium的前
appium+python自动化31-android_uiautomator定位,,前言appium的前
前言
appium的前身就是封装android的uiautomator这个框架来的,所以uiautomator的一些定位方法也可以用
text
1.通过text文本定位语法
new UiSelector().text("text文本")
2.文本比较长的时候,可以用textContains模糊匹配,只要文本包含匹配内容就可以了。
new UiSelector().textContains("包含text文本")
3.textStartsWith是以某个文本开头的匹配
new UiSelector().textStartsWith("以text文本开头")
4.正则匹配textMatches,这个需要配合正则表达式,就不举例了。
new UiSelector().textMatches("正则表达式")
# coding:utf-8from appium import webdriverdesired_caps = { 'platformName': 'Android', 'deviceName': '127.0.0.1:62001', 'platformVersion': '4.4.2', 'appPackage': 'com.baidu.yuedu', 'appActivity': 'com.baidu.yuedu.splash.SplashActivity', 'noReset': 'true', 'resetKeyboard': 'true', 'unicodeKeyboard': 'true' }driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)# 等主页面activity出现driver.wait_activity(".base.ui.MainActivity", 10)# 1.textloc_text = 'new UiSelector().text("图书")'driver.find_element_by_android_uiautomator(loc_text).click()# # 2.textContains# loc_textContains = 'new UiSelector().textContains("图")'# driver.find_element_by_android_uiautomator(loc_textContains).click()# # 3.textStartsWith# loc_textStart = 'new UiSelector().textStartsWith("图")'# driver.find_element_by_android_uiautomator(loc_textStart).click()
resourceId
1.resourceId根by_id一样
new UiSelector().resourceId("id")
# resourceId定位loc_id = 'new UiSelector().resourceId("com.baidu.yuedu:id/webbooktitle")'driver.find_element_by_android_uiautomator(loc_id).click()
className
1.页面上的class属性一般不唯一,多半用在复数定位时候。比如通过class属性定位‘排行‘这个按钮下标就是2。
new UiSelector().className("className")
# className复数定位loc_class = 'new UiSelector().className("android.widget.TextView")'driver.find_elements_by_android_uiautomator(loc_class)[2].click()
description
1.由于这个app的contenet-des属性都是空的,就不用代码演示了,跟上面方法一样。
new UiSelector().description("contenet-des属性")
参考代码
# coding:utf-8from appium import webdriverfrom time import sleepdesired_caps = { 'platformName': 'Android', 'deviceName': '127.0.0.1:62001', 'platformVersion': '4.4.2', 'appPackage': 'com.baidu.yuedu', 'appActivity': 'com.baidu.yuedu.splash.SplashActivity', 'noReset': 'true', 'resetKeyboard': 'true', 'unicodeKeyboard': 'true' }driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)# 等主页面activity出现driver.wait_activity(".base.ui.MainActivity", 10)# 1.textloc_text = 'new UiSelector().text("图书")'driver.find_element_by_android_uiautomator(loc_text).click()# # 2.textContains# loc_textContains = 'new UiSelector().textContains("图")'# driver.find_element_by_android_uiautomator(loc_textContains).click()# # 3.textStartsWith# loc_textStart = 'new UiSelector().textStartsWith("图")'# driver.find_element_by_android_uiautomator(loc_textStart).click()sleep(2)# resourceId定位'小说'loc_id = 'new UiSelector().resourceId("com.baidu.yuedu:id/webbooktitle")'driver.find_element_by_android_uiautomator(loc_id).click()sleep(2)# className复数定位loc_class = 'new UiSelector().className("android.widget.TextView")'driver.find_elements_by_android_uiautomator(loc_class)[2].click()
appium+python自动化31-android_uiautomator定位
相关内容
- Python测试工具——nose,pythonnose,1、nose 特点:
- [python]如何理解uiautomator里面的 child, child_by_text, siblin
- error: <class 'xml.parsers.expat.ExpatError'&a
- python文件基础之(文件操作),,在之前学习了pyth
- [python]RobotFramework自定义库实现UI自动化,robotframeworku
- python2.7和python3.6共存,使用pip安装第三方库,python2.7
- Python模块中requests模块的基本用法详解,pythonrequests,
- python文件读取 readlines()方法之坑,pythonreadlines,一、需求
- IIS 部署 python web框架 Flask,pythonflask,IIS的安装就不说了
- python基础学习11天,作业题,python11天,1. 文件a.txt
评论关闭