Appium_Java_API

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

 

posted @ 2019-01-30 16:47  jiguanghover  阅读(169)  评论(0编辑  收藏  举报