9

I am testing an app and on most of the screens I see that there are elements that have the same class "android.widget.TextView" with same index number "0". All other properties also same, only exceptions are the "text" and "bound".

I have "Skip", "Next" and "Skip Next 3" as texts on the screen which has the same attribute other than the text and bounds Attribute. I need to know how I can point appium to click on the desired item .. say I want to click on "Next", how can I do this. I am using Python for the scripting.

nhrcpt
  • 862
  • 3
  • 21
  • 51
  • You need to look into how to use webdriver to location the widget using the button with the word "Next". I dont have it handy, but that is what you need. – dazza5000 Feb 23 '18 at 03:51

3 Answers3

2

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

for element in webdriver.find_elements_by_class_name('android.widget.TextView'):
     if element.text == "Next":
          element.click()
Chuk Ultima
  • 987
  • 1
  • 11
  • 21
2

Doing as Chuk Ultima said will work, but if you have lots of TextView it may take a while.

You can use:

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

See more usages in http://www.automationtestinghub.com/uiselector-android/

tcardoso
  • 668
  • 3
  • 8
  • 20
1

Well, In my case I finally solved the problem using traversing through nodes like I created xpath to get the Text (time value) from a particular location like this:

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 this is a tedious process, but for the time being this is the solution for me.

nhrcpt
  • 862
  • 3
  • 21
  • 51
  • Lookt at point 1: https://www.joecolantonio.com/2018/01/25/top-8-appium-mobile-test-automation-mistakes-avoid/ – tcardoso Feb 24 '18 at 09:41