Search code examples
c#selenium-webdriverappiumwinappdriver

Appium: How to write for-loop to click through buttons with index?


I am using C# and Appium to automate a Windows 10 software for my company. On the bookmarks bar, there is a list of tabs that I want to click through. They are buttons that are indexed from 15-20. Rather than doin

driver.FindElementsByXpath("//Pane/Button[15]").Click();

driver.FindElementsByXpath("//Pane/Button[16]").Click();

driver.FindElementsByXpath("//Pane/Button[17]").Click();

driver.FindElementsByXpath("//Pane/Button[18]").Click();

driver.FindElementsByXpath("//Pane/Button[19]").Click();

and so on, how can I write a for loop that will loop through and click onbutton[15] to button[30]? Is this even possible with Appium? Thanks!


Solution

  • I figured it out. I should have put the WindowsElement line in side the for loop. Probably not the most optimal solution, but it does what I want it to. Thanks everyone. Also thanks @Selvin for the roast.

    for(int i=15; i<=30; i++)
            {
                WindowsElement buttons = FBsession.FindElementsByXPath("//Pane/Button")[i];
                buttons.Click();
            }