The problem

I have two buttons with the same name in Windows program. So I do: "self.driver.find_element_by_name("button name").click()" - it selects the first one, but I need the second one.

I tried to use Inspect.exe to find AutomationId, but in the case it doesn't show AutomationId. There are name, processId etc

So how to choose the second button? Thanks!


  • Appium python client version: 0.46
  • Desktop OS/version used to run Appium: Ubuntu 18.04
  • Platform/version under test: Windows Server 2016
  • Real device or emulator/simulator: VPS
  • Is there no equivalent of a find elements method - something which will return a collection of elements. Jul 7, 2019 at 11:57

2 Answers 2


Instead of running the click straight away you can iterate over the results and see if they are suitable before clicking them.

foreach (button in self.driver.find_elements_by_name("button_name"))
   if button.property == 'what i want'

You can add other constraints on the button by adjusting the if statements. Nothing inside the foreach will run if there are no matching buttons.

  • It's not a python example. ====================================================================== ERROR: test_addition (main.SimpleCalculatorTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "calculatortest.py", line 73, in test_addition for i in self.driver.find_element_by_name("Дополнительные отчеты и обработки"): TypeError: 'WebElement' object is not iterable Jul 9, 2019 at 18:13

in xpath you can pass the index of the elements, for example if you want the first button to be selected give this

self.driver.find_element_by_xpath((//path to your button)[0]).click()"

if you want second one

self.driver.find_element_by_xpath((//path to your button)[1]).click()"

Please check whether index starting from 0 or 1 in your DOM

  • What is the language? I use python for Windows Jul 9, 2019 at 18:15
  • find_element_by_xpath() this is python-appium function itself Jul 10, 2019 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.