appium===常用方法介绍,元素定位
2018-05-31 10:54
666 查看
https://testerhome.com/topics/3711
元素定位方法:
find_element_by_android_uiautomator ,使用uiautomator定位,后面参数更改即可:
-
UiSelector().text 根据text属性进行定位
self.driver.find_element_by_android_uiautomator('new UiSelector().text("33001122")')
-
UISelector.textContains 根据text属性模糊定位
e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("1122")')
-
UISelector.textStartsWith 根据text的前面几位是否与text一致来定位
e7 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("33")')
-
UISelector.textMatches 通过正则表达式和text来进行定位,正则不怎么会,先不扩展了
-
UISelector.className 通过class来进行定位,合理利用层级定位,例如找到所有的Edittext然后根据text定位
e8 = self.driver.find_element_by_android_uiautomator('new UiSelector()' '.className("android.widget.EditText")' '.textContains("33")')
-
UISelector.classNameMatches 通过正则表达式和class来进行定位
还有UiSelector.descriptionMatches 、 UiSelector.descriptionStartWith 、UiSelector.description
from appium import webdriver from time import sleep s_time = 3 desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '7' desired_caps['deviceName'] = 'ssssssssssssssssss' desired_caps['appPackage'] = 'com.android.calculator2' desired_caps['appActivity'] = '.Calculator' driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # by_id driver.find_element_by_id("digit_1").click() # by_xpath driver.find_element_by_xpath("//android.widget.Button[@text='5']").click() driver.find_element_by_id("digit_9").click() # by_accessibility_id driver.find_element_by_accessibility_id("删除").click() # by_class_name driver.find_elements_by_class_name("android.widget.Button")[10].click() print("pass") driver.find_element_by_id("digit_5").click() # by_android_uiautomator driver.find_element_by_android_uiautomator('new UiSelector().text("9")').click() driver.find_element_by_id("digit_6").click() driver.find_element_by_id("eq").click() sleep(s_time) driver.quit()
相关文章推荐
- 在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素。其中By类的常用定位方式共八种,现分别介绍如下
- Selenium Webdriver元素定位的八种常用方法
- Selenium Webdriver元素定位的八种常用方法
- 八 Appium常用方法介绍
- 关于robotframework,app,appium的xpath定位问题及常用方法
- Appium 元素定位方法(Java版)
- python+appium重写元素定位的方法
- 七 Appium常用方法介绍
- Appium 关于 appium 的原生控件的 xpath 定位问题及常用方法
- Selenium Webdriver元素定位八中常用方法
- Appium常用方法介绍
- Appium基于安卓的元素定位方法
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍
- appium 元素定位方法
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍
- APPIUM处理纯web应用元素定位方法
- Appium for Android元素定位方法
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍
- Appium Android 元素定位方法 原生+H5
- Appium for Android元素定位方法