diff --git a/README.md b/README.md index 7e90eb27e..2bd8d582a 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,22 @@ els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickab self.assertIsInstance(els, list) ``` +### Finding elements by Android viewtag search + +This method allows finiding elements using [View#tags](https://developer.android.com/reference/android/view/View#tags). +This method works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). + +Adds the methods `driver.find_element_by_android_viewtag` and `driver.find_elements_by_android_viewtag`. + +```python +el = self.driver.find_element_by_android_viewtag('a tag name') +self.assertIsNotNone(el) +``` + +```python +els = self.driver.find_elements_by_android_viewtag('a tag name') +self.assertIsInstance(els, list) +``` ### Finding elements by iOS predicates diff --git a/appium/webdriver/common/mobileby.py b/appium/webdriver/common/mobileby.py index 3e77c51eb..ce76838b2 100644 --- a/appium/webdriver/common/mobileby.py +++ b/appium/webdriver/common/mobileby.py @@ -20,5 +20,6 @@ class MobileBy(By): IOS_UIAUTOMATION = '-ios uiautomation' IOS_CLASS_CHAIN = '-ios class chain' ANDROID_UIAUTOMATOR = '-android uiautomator' + ANDROID_VIEWTAG = '-android viewtag' ACCESSIBILITY_ID = 'accessibility id' IMAGE = '-image' diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 94deb79b5..acd40e30c 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -341,6 +341,30 @@ def find_elements_by_android_uiautomator(self, uia_string): """ return self.find_elements(by=By.ANDROID_UIAUTOMATOR, value=uia_string) + def find_element_by_android_viewtag(self, tag): + """Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android. + It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). + + :Args: + - tag - The tag name of the view to look for + + :Usage: + driver.find_element_by_android_viewtag('a tag name') + """ + return self.find_element(by=By.ANDROID_VIEWTAG, value=tag) + + def find_elements_by_android_viewtag(self, tag): + """Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android. + It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). + + :Args: + - tag - The tag name of the view to look for + + :Usage: + driver.find_elements_by_android_viewtag('a tag name') + """ + return self.find_elements(by=By.ANDROID_VIEWTAG, value=tag) + def find_element_by_image(self, png_img_path, match_threshold=DEFAULT_MATCH_THRESHOLD): """Finds a portion of a screenshot by an image.