Here’s a code snippet of what we’re currently using:
string visibleClassChain = string.Format("**/XCUIElementTypeStaticText[`name=='labelCell' AND value CONTAINS[cd] '{0}' AND visible == true`]", cellToSelect);
while (!Application.ElementExistByClassChain(visibleClassChain))
{
Utility.ScrollIOSScreen();
}
var cellToSelect = Application.FindElementByClassChain(visibleClassChain, "cell to select");
Command.Click(cellToSelect , "Click cell");
var detail = Application.FindElementByClassChain("**/XCUIElementTypeButton[`name=='ButtonDetails'`]", "Details button"); /*<-- Screen scrolls here if cell selected is not from the first cells shown upon load / from way below the list*/
Command.Click(detail, "Details click");
Command.Click simply does the following:
public static void Click(IOSElement element, string name)
{
try
{
driver.Tap(1, element, 200);
}
catch (Exception ex)
{
throw new ApplicationException("Unable to click " + name, ex);
}
}
Utility.ScrollIOSScreen simply does a driver.swipe to the screen to show the next cells.
FindElementByClassChain’s implementation is below:
public static IOSElement FindElementByClassChain(string classChain, string elementName)
{
try
{
return driver.FindElement("-ios class chain", classChain);
}
catch (Exception e)
{
if (elementName == "")
{
var elementId = classChain.ToString().Split(new string[] { ":" }, StringSplitOptions.None);
elementName = elementId.Last().Trim();
}
throw new Exception(string.Format("{0} element was not found", elementName), e);
}
}