appium 元素定位与交互中文文档
来源:互联网 发布:淘宝客服工作总结100字 编辑:程序博客网 时间:2024/05/22 10:44
元素定位与交互
Appium支持一个Webdriver元素定位方法的子集
- find by "tag name" (i.e., 通过UI的控件类型)
- find by "name" (i.e., 通过元素的文本, 标签, 或者开发同学添加的id标示, 比如accessibilityIdentifier)
- find by "xpath" (i.e., 具有一定约束的路径抽象标示, 基于XPath方式)
###标签名抽象映射
你可以使用UIAutomation的控件类型用于标签名, 或者使用简化的映射, 可以参考下如下例子
https://github.com/appium/appium/blob/master/lib/uiauto/lib/mechanic.js#L29
(官方文档外的补充)
对于Android下的元素对应, 可以参考
https://github.com/appium/appium/blob/master/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/AndroidElementClassMap.java
例子
找到屏幕上所有的UIAButtons
WD.js:
driver.elementsByTagName('button', function(err, buttons) { // tap all the buttons var tapNextButton = function() { var button = buttons.shift(); if (typeof button !== "undefined") { button.click(function(err) { tapNextButton(); }) } else { driver.quit(); } } tapNextButton();});
Ruby:
buttons = @driver.find_elements :tag_name, :buttonbuttons.each { |b| b.click }
Python:
[button.click() for button in driver.find_elements_by_tag_name('button')]
找到所有文本内容(或者accessibilityIdentifier)为"Go"的元素
WD.js:
driver.elementByName('Go', function(err, el) { el.tap(function(err) { driver.quit(); });});
Ruby:
@driver.find_element(:name, 'Go').click
Python:
driver.find_element_by_name('Go').click()
找到以"Hi, "开头的导航条元素
WD.js:
driver.elementByXpath('//navigationBar/text[contains(@value, "Hi, ")]', function(err, el) { el.text(function(err, text) { console.log(text); driver.quit(); });});
Ruby:
@driver.find_element :xpath, '//navigationBar/text[contains(@value, "Hi, ")]'
通过tagName查找元素
Java:
driver.findElement(By.tagName("button")).sendKeys("Hi");WebELement element = findElement(By.tagName("button"));element.sendKeys("Hi");List<WebElement> elems = findElements(By.tagName("button"));elems.get(0).sendKeys("Hi");
Python:
driver.find_elements_by_tag_name('tableCell')[5].click()
FindAndAct<a name="findandact"></a>
你也可以通过一行命令来完成元素的查找和交互(只适用于IOS)
举个例子, 你可以通过一次调用来实现查找一个元素并点击它, 使用的命令是mobile: findAndAct
Python:
args = {'strategy': 'tag_name', 'selector': 'button', 'action': 'tap'}driver.execute_script("mobile: findAndAct", args)
用一个滑动手势进行下拉刷新
Python:
js_snippet = "mobile: swipe"args = {'startX':0.5, 'startY':0.2, 'startX':0.5, 'startY':0.95, 'tapCount':1, 'duration':10}driver.execute_script(js_snippet, args)
备注: driver.execute_script() 可以在 Automating Mobile Gestures: Alternative access method) 找到说明
使用Appium Inspector来定位元素
(翻译备注: 这个工具目前只有Mac版本, 如果你使用的是windows, 可以使用android自带的traceview工具来获得元素的位置)
Appium提供了一个灵活的工具Appium Inspector, 允许你在app运行的时候, 直接定位你正在关注的元素. 通过Appium Inspector(靠近start test按钮的i标示文本), 你可以通过点击预览窗口上的控件来获得它的name属性, 或者直接在UI导航窗口中定位
概述
Appium Inspector有一个简单的布局, 全部由如下窗口组成.
UI导航器, 预览, 录制与刷新按钮, 和交互工具
例子
启动Appium Inspector后, (通过点击app右上的小"i"按钮), 你可以定位任何预览窗口中的元素. 作为测试, 我正在查找id为"show alert"的按钮
要找到这个按钮的id, 在定位预览窗口中我点击了"show alert"按钮, Appium Inspector在UI导航窗口中高亮显示了这个元素, 然后展示了刚被点击按钮的id和元素类型
- appium 元素定位与交互中文文档
- Appium 元素定位
- Appium自动化元素定位
- appium定位元素
- appium元素定位问题
- Appium元素定位汇总
- appium关于定位元素
- 中文 Appium API 文档
- appium中文api文档
- appium定位元素java篇
- appium定位元素java篇
- appium定位元素java篇
- appium定位元素java篇
- appium定位元素java篇
- appium定位元素java篇
- appium 如何定位webview元素
- Appium-Android元素定位方式
- appium元素定位(12)
- UVa 489 侩子手游戏
- ======android api 中文地址======
- 数据抓取问题之URL特殊字符(如ѐ)
- NVIDIA Jetson TK1学习与开发(八):图文详解OpenGL在Jetson TK1上的安装和使用
- hdu-4818-RP problem(高斯消元)
- appium 元素定位与交互中文文档
- sql连接
- Android 属性动画(Property Animation) 完全解析
- ecshop foreach 循环内动态改变标签样式
- USACO:2.1.3 Sorting a Three-Valued Sequence 三值的排序
- HDOJ 最少拦截系统 1257
- ios info.plist 详解
- 【人生感悟】
- android隐藏软键盘代码