Appium + python - automator定位操作
# coding:utf-8
from appium import webdriver
from time import sleep desired_caps = {
'platformName': 'Android',
'deviceName': '127.0.0.1:62001',
'platformVersion': '5.1.1',
'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.text
loc_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() """
参考博客:https://www.cnblogs.com/yoyoketang/p/7833554.html
1.通过text文本定位语法
new UiSelector().text("text文本") 2.文本比较长的时候,可以用textContains模糊匹配,只要文本包含匹配内容就可以了。
new UiSelector().textContains("包含text文本") 3.textStartsWith是以某个文本开头的匹配
new UiSelector().textStartsWith("以text文本开头") 4.正则匹配textMatches,这个需要配合正则表达式,就不举例了。
new UiSelector().textMatches("正则表达式") 5.resourceId根by_id一样
new UiSelector().resourceId("id") 6.页面上的class属性一般不唯一,多半用在复数定位时候。
比如通过class属性定位'排行'这个按钮下标就是2。
new UiSelector().className("className") 7.由于这个app的contenet-des属性都是空的,就不用代码演示了,跟上面方法一样。
new UiSelector().description("contenet-des属性")
"""
Appium + python - automator定位操作的更多相关文章
- Appium + python - automator定位升级版操作
# coding:utf-8 """参考博客链接:https://www.cnblogs.com/yoyoketang/p/7843819.html"" ...
- Appium + python - long_press定位操作实例
from appium.webdriver.common.touch_action import TouchActionfrom appium import webdriverimport timei ...
- Appium + Python -------------元素定位
说在前面 1.https://github.com/appium/python-client/tree/master/test 里面有一些test ,可以看看,研究研究 2.学会使用 uiautom ...
- Appium+python自动化4-元素定位uiautomatorviewer
前言 环境搭建好了,下一步元素定位,元素定位本篇主要介绍如何使用uiautomatorviewer,通过定位到页面上的元素,然后进行相应的点击等操作. uiautomatorviewer是androi ...
- appium+python自动化43-微信公众号webview操作
前言 上一篇已经解决切换到微信公众号的webview上了,但是定位webview上元素的时候一直提示找不到,打印page_source也找不到页面上的元素,这个问题困扰了一整天,还好最后找到了原因, ...
- Appium+python自动化12-appium元素定位
前言 appium定位app上的元素,可以通过id,name.class这些属性定位到 一.id定位 1.appium的id属性也就是通过UI Automator工具查看的resource-id属性
- appium+python自动化38-adb shell按键操作(input keyevent)
前言 接着上篇介绍input里面的按键操作keyevent事件,发送手机上常用的一些按键操作 keyevent 1.keyevent事件有一张对应的表,可以直接发送对应的数字,也可以方式字符串,如下两 ...
- appium+python自动化31-android_uiautomator定位
前言 appium就是封装android的uiautomator这个框架来的,所以uiautomator的一些定位方法也可以用 text 1.通过text文本定位语法 new UiSelector() ...
- appium+python自动化32-android_uiautomator定位进阶版
前言 上一篇介绍uiautomator的定位方式都是类似这种'new UiSelector().xxx("xxx")',看起非常长,我也记不住,这很不python.于是本篇优化了定 ...
随机推荐
- linu下nginx的安装
这里用到的环境是nginx-1.8.0,linux用的是CentOS-7-x86_64-DVD-1804.iso版本 1 什么是nginx Nginx ("engine x") ...
- bootstrap中chosen控件样式有时会冲突
加上这句话试试 $(".chosen-container").css("width","100%"); 或者 100%改成 100px试试
- 我的FPGA
转眼间我都工作三个年头了,这两年多时间我一直从事着FPGA测试工作,从一开始的懵懂无知,到现在的些许理解,我想记录和分享我对FPGA测试的理解. 之所以选择在博客园写这样,是我发现在这里阅览文章不需要 ...
- HDU3336Count the string
HDU3336Count the string Problem Description It is well known that AekdyCoin is good at string proble ...
- 思维风暴 codeforces (1060A) Phone Numbers
这个题我真是我的问题,我看到这种题直接就想着怎么用string去枚举破解,开了一个数组去做结果模拟失败,可能开个stl容器能做的好一点...但是这个题完全不是这样做的...实际上直接比较8的个数和合法 ...
- map put
public class test { static Map<String, Map<String, Integer>> mapB = new HashMap<Strin ...
- 给sunpinyin加速
因为sunpinyin词库一大就会卡,因此需要自己添加一个脚本给sunpinyin加速. 加速的原理就是把词库添加到内存,现在内存都这么大,根本不在乎这么几兆,当然输入体验更重要啦- 首先先建一个脚本 ...
- [bzoj3224]普通平衡树[Treap]
Treap 的各种操作,模板题,要再写几遍 #include <iostream> #include <algorithm> #include <cstdio> # ...
- Markdown 基本使用
My First Markdown 标签(空格分隔): 未分类 # Markdown 11种基本语法## 设置标题在此输入正文标题设置(让字体变大,和word的标题意思一样)在Markdown当中设置 ...
- LeetCode 122 Best Time to Buy and Sell Stock II(股票买入卖出的最佳时间 II)
翻译 话说你有一个数组,当中第i个元素表示第i天的股票价格. 设计一个算法以找到最大利润. 你能够尽可能多的进行交易(比如.多次买入卖出股票). 然而,你不能在同一时间来多次交易. (比如.你必须在下 ...