appium_2 查找元素
2015-07-28 17:15
183 查看
AndroidDriver类
继承图
主要方法
可以看出主要是findElementByAndroidUIAutomator 要借助android sdk自带的uiautomatorviewer.bat 工具
具体方法 测试成功的
参考
1、通过类名的方法
此方法一会获取到多个
2、通过resouceId 只适合4.3以上的
只有android 4.3以上才会看到resouceId,具以下方法才能找得到元素
代码如下
3、通过android:contentDescription属性
uiautomatorviewer.bat中的content-desc属性
对应的方法
4、xpath
@text 是button的text属性
//不可省图
5、UIAutomator
instance(0) button中的第一个元素
\” 不能替换到’
6、通过name
name android的text属性
7、查看界面关系
界面的xml文件
详情参考
继承图
主要方法
可以看出主要是findElementByAndroidUIAutomator 要借助android sdk自带的uiautomatorviewer.bat 工具
具体方法 测试成功的
参考
1、通过类名的方法
By by1 = By.className("android.widget.Button"); WebElement el = driver.findElement(by1); el.click();
此方法一会获取到多个
2、通过resouceId 只适合4.3以上的
只有android 4.3以上才会看到resouceId,具以下方法才能找得到元素
代码如下
By by2 = By.id("cn.chinagps.jicha:id/car_license_et"); // TouchableElement e2 = (TouchableElement) driver.findElement(by2);
3、通过android:contentDescription属性
uiautomatorviewer.bat中的content-desc属性
对应的方法
driver.findElementByAccessibilityId("button");
4、xpath
driver.findElementByXPath("//android.widget.Button[contains(@text,'buttontext')]").click();
@text 是button的text属性
//不可省图
5、UIAutomator
driver.findElementByAndroidUIAutomator("new UiSelector().text(\"buttontext\")").click(); driver.findElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.Button\")").click(); driver.findElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.Button\").instance(0)").click();
instance(0) button中的第一个元素
\” 不能替换到’
6、通过name
driver.findElementByName("buttontext").click();
name android的text属性
7、查看界面关系
driver.getPageSource();
界面的xml文件
详情参考
相关文章推荐
- [iOS]NSString到底使用Copy还是使用Strong属性,有什么区别
- iOS 中如何预览HTML中的图片
- iOS中的KVC
- Androidproject夹
- 基于swiftype应用于Hexo-Yilia-主题的站内搜索引擎
- iOS通过app1调用app2,同时app隐藏图标
- Swift学习笔记系列——(12)继承
- 09应用输入经理旋转场景--《猿学校课程Unity3d》
- iphone-only apps icon
- android进程间通信:使用AIDL
- Gios WORD .NET Library (using RTF specification)
- iOS APP禁止横屏
- Unity协程(Coroutine)原理深入剖析再续
- [不明所以]android 5.0 couldn't find "libmsc.so"
- [不明所以]android 5.0 couldn't find "libmsc.so"
- Unity笔记 SPACE SHOOTER 实例详解
- Unity时钟定时器插件——Vision Timer源码分析之一
- Unity协程(Coroutine)管理类——TaskManager工具分享
- Android Application使用
- [Link]用HTML5/CSS3/JS开发Android/IOS应用