Search code examples
appiumappium-androidpython-appium

Is there a way to get all the elements with the same class type


Using Appium python client, I want to get all the view returned by;

elements = driver.find_elements_by_class_name(‘foo’) in a container; like list or other.

Can I try

elements = driver.find_elements_by_class_name(‘foo’)
for i in len(elements)
   list_element + i = elements

Then I can access a list of elements all belonging to the class using list_element?


Solution

  • Yes, you can do it. Let say you want click:

    elements = driver.find_elements_by_class_name('foo')
    for element in elements:
        element.click()
    

    Or if you want access particular element in elements, you can use index:

    elements = driver.find_elements_by_class_name('foo')
    #first element
    elements[0].click()