0

I am learning appium (mobile automation) using python.

I have a scenario where I have a listView and I have to iterate through each item and then click back until all items are clicked.

I am using following code:

def test_selectingEveryOption(self):
        availableOptions = self.driver.find_elements_by_xpath('//android.widget.ListView')
        for options in availableOptions:
            availableOptions[options].click()
            self.driver.back()

availableOptions is the webElement that have the list. When I run above piece of code, I get TypeError: list indices must be integers or slices, not WebElement

Since availableOptions is webElement, how can I get its list items as integers and then iterate over them?

UzIT
  • 51
  • 1
  • 7

1 Answers1

1

browser.find_elements_by_class_name("myClass") returns a list of WebElements. So.. in your for-loop, each iteration produces a WebElement, not an integer index... you don't need to use indexes at all.

for element in self.driver.find_elements_by_xpath('//android.widget.ListView'):
    element_contents = element.get_attribute('innerHTML')
  • But I'm getting noSuchElementException for the list.. NoSuchElementException: Message: This element does not have the 'innerHTML' attribute – UzIT Jun 12 '18 at 07:02
  • I'm not very well versed with python-appium but how about you find out you print all the attributes associated with 'element' inside the loop and see which one suits your needsm – Tarush Nagpal Jun 12 '18 at 10:27