1. driver.findElement(MobileBy.AndroidUIAutomator("邀请")).click();
2. driver.findElementById("resourceId").click();
3. import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
4. assertNotEquals(driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null);
5. assertNotEquals(driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0);
6. assertNotEquals(driver.findElementById("android:id/content")
.findElement(MobileBy.AccessibilityId("Graphics")).getText(), null);
7.assertEquals(driver.findElementById("android:id/content").findElements(MobileBy.AccessibilityId("Graphics")).size()
8. driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));
9. editElement.sendKeys("value");
10. driver.findElementByAccessibilityId("Views").click();
11. AndroidElement list = driver.findElement(By.id("android:id/list"));
MobileElement radioGroup = list.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector())
.scrollIntoView("+ "new UiSelector().text(\"Radio Group\"));"));
12.driver.findElementByAndroidUIAutomator("new UiSelector().index(0)");
13. findElementByAndroidUIAutomator("text(\"Accessibility\")");
14. 通过index查找: driver.find_element_by_android_uiautomator("new UiSelector().index(5)")
15. 通过text查找: driver.find_element_by_android_uiautomator("new UiSelector().text(\"6\")")
16. 通过clickable查找: driver.find_element_by_android_uiautomator("new UiSelector().clickable(true)")
17. 通过content-desc查找: driver.find_element_by_android_uiautomator("new UiSelector().description(\"\equals")")
18. 通过resource-id查找: driver.find_element_by_android_uiautomator("new UiSelector().resourceId(\"com.android.calculator2:id/digit_3\")")
19. 通过两个以上属性共同查找: driver.find_element_by_android_uiautomator("new UiSelector().clickable(true).index(5)")
20. 使用ByName定位
路径: appium\node_modules\appium-android-driver\build\lib
修改文件:driver.js,只需要修改其中一行即可
this.locatorStrategies = ['xpath', 'id', 'class name', 'accessibility id', '-android uiautomator','name'];--------再此行代码中添加上name
修改完成之后,保存文件,再次重启appium服务,就可以继续使用ByName定位
21) text 方式
driver.find_element_by_android_uiautomator('new UiSelector().text("%s")')
22) description 方式
driver.find_element_by_android_uiautomator('new UiSelector().description("%s")')
23) className 方式
driver.find_element_by_android_uiautomator('new UiSelector().className("%s")')
24) index 方式
driver.find_element_by_android_uiautomator('new UiSelector().index("%s")')
25) className + index 方式
driver.find_element_by_android_uiautomator(
'new UiSelector().className("%s").childSelector(new UiSelector().index("%d"))')
26) 伪xpath方法定位
driver.find_element_by_android_uiautomator(‘new UiSelector().text("Custom View").fromParent(
new UiSelector().text("Accessibility Service"))‘).click() #通过同级元素定位同级元素
driver.find_element_by_android_uiautomator(‘new UiSelector().className("android.widget.ListView")
.childSelector(new UiSelector().text("Custom View"))‘).click() #通过父级元素定位子集元素
27) resourceId 方式
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("%s")')

参考资料:
1) https://github.com/appium/java-client/tree/master/docs
2) http://appium.io/docs/en/writing-running-appium/caps/index.html
3) On Windows, ensure that you always run Appium in Administrator mode
4)https://blog.csdn.net/eldencheng/article/details/79491579
5) https://testerhome.com/topics/10071

Appium_Java_API的更多相关文章

随机推荐

  1. Codefroces B. Hamming Distance Sum

    Genos needs your help. He was asked to solve the following programming problem by Saitama: The lengt ...

  2. SpringMVC与SpringBoot返回静态页面遇到的问题

    1.SpringMVC静态页面响应 package com.sv.controller; import org.springframework.stereotype.Controller; impor ...

  3. angularjs 页面缓存及动态刷新解决方案

    一.准备工作 框架:angularjs ui组件库:ionic1 二.页面缓存cache 路由设置cache参数,true为缓存,false为不缓存,代码如下: angular.module('app ...

  4. Java基础关于Map(字典)的方法使用

    Java基础关于Map(字典)的方法使用 java中一般用map与hashmap来创建一个key-value对象 使用前提是要导入方法包: import java.util.HashMap: impo ...

  5. C# Arcgis Engine 获得鼠标按下位置的要素

    public IFeature GetFeatureOnMouseDown(IPoint point) { try { ILayer layer = Common.GetLayerByName(mMa ...

  6. 【HDU】5249-KPI(线段树+离散化)

    好久没写线段树都不知道怎么写了... 很easy的线段树二分问题 #include<cstdio> #include<set> #include<queue> #i ...

  7. I帧、P帧和B帧的特点

    I帧:帧内编码帧 I帧特点: 1.它是一个全帧压缩编码帧.它将全帧图像信息进行JPEG压缩编码及传输; 2.解码时仅用I帧的数据就可重构完整图像; 3.I帧描写叙述了图像背景和运动主体的详情; 4.I ...

  8. [转]C语言字节对齐问题详解

    C语言字节对齐问题详解 转载:https://www.cnblogs.com/clover-toeic/p/3853132.html 引言 考虑下面的结构体定义: typedef struct{ ch ...

  9. OpenCASCADE 3 Planes Intersection

    OpenCASCADE 3 Planes Intersection eryar@163.com Abstract. OpenCASCADE provides the algorithm to sear ...

  10. 带你彻彻底底弄懂Scroller

    Scroller的使用 这是一个滑动帮助类.并不能够使View真正的滑动,而是依据时间的流逝.获取插值器中的数据.传递给我们.让我们去配合scrollTo/scrollBy去让view产生缓慢滑动,产 ...