Choosing an element in Appium / Android using Python with the same class index and one another in UIAutomatorViewer

I am testing an application, and on most screens I see that there are elements that have the same class "android.widget.TextView" with the same index number "0". All other properties are also the same, only exceptions are β€œtext” and β€œlinked”.

I have "Skip", "Next" and "Skip next 3" in the form of texts on the screen that has the same attribute different from the text attribute and borders. I need to know how I can specify appium to click on the desired item. Say that I want to click Next, how can I do this. I use Python for scripting.

+8
python android appium appium-android uiautomatorviewer
source share
3 answers

You can search for all matching web elements with the same class name that will return you a list of matching elements. Then you iterate over the elements found and compare their text, for example:

for element in webdriver.find_elements_by_class_name('android.widget.TextView'): if element.text == "Next": element.click() 
+2
source share

Execution, as Chuk Ultima said, will work, but if you have a lot of TextViews, this may take some time.

You can use:

 ((AndroidDriver<MobileElement>)driver).findElementByAndroidUIAutomator("new UiSelector().text(\"Next\")"); 

Learn more about using at http://www.automationtestinghub.com/uiselector-android/

+2
source share

Well, in my case, I finally solved the problem using transitions through nodes, as I created xpath to get the text (time value) from a specific place, for example:

 Time = self.driver.find_element_by_xpath('//android.widget.LinearLayout[@index=2]/android.view.ViewGroup[@index=0]/android.view.ViewGroup[@index=0]/android.view.ViewGroup[@index=0]/android.view.ViewGroup[@index=3]/android.view.ViewGroup[@index=0]/android.widget.TextView[@index=0]').get_attribute('text') 

I understand that this is a tedious process, but so far this solution is for me.

+1
source share

All Articles