// ************ DATE 10/16/2020 ************ // ***** IMPORTANT: All Click by XPATH will search an element and then click it. // ************ --------------- ************ #region BY XPATH /// <summary> /// Finds the first element in the screen that matches the xPath criteria and then click it. /// </summary> /// <param name="position">Position to match a specific element</param> /// <param name="elem">Represents the Enum in Share class</param> /// <param name="widget">boolean if this is a widget</param> public static void ByXPath(int position, Share.Element elem = Share.Element.EditText, bool widget = true) { try { AppiumWebElement element = GetControl.ByXPath(position, elem, widget); element.Click(); } catch (Exception ex) { Assert.Fail("ClickByXPath threw an exception: " + ex.Message); } }
/// <summary> /// Finds the first element in the screen that matches the xPath criteria and then click it. /// </summary> /// <param name="text">text to match the element to be found</param> /// <param name="elem">Represents the Enum in Share class</param> /// <param name="widget">boolean if this is a widget</param> public static void ByXPath(string text, Share.Element elem = Share.Element.EditText, bool widget = true) { try { var elements = GetControl.CollectionByXPath(elem, widget); foreach (var element in elements) { if (element.Text.Contains(text)) { element.Click(); } } } catch (Exception ex) { Assert.Fail("ClickByXPath threw an exception: " + ex.Message); } }
// ************ DATE 10/16/2020 ************ // All the Builders used till date. // ***** IMPORTANT: This Builder return a new class of type By from OpenQA.Selenium // ************ --------------- ************ #region BUILDERS /// <summary> /// Builds a By object using the enum pass /// </summary> /// <param name="by">Represents the Enum in Share class.</param> /// <param name="value">Value used to find the element.</param> /// <param name="element">The element type.</param> /// <param name="isWidget">True if it is a widget, false if it is a View.</param> public static By BuildBy(Share.By by, Share.Element element, bool isWidget = true) { var attribute = Misc.BuildElement(isWidget, element); By _by = null; switch (by) { case Share.By.ClassName: _by = By.ClassName(attribute); break; case Share.By.CssSelector: _by = By.CssSelector(attribute); break; case Share.By.Id: _by = By.Id(attribute); break; case Share.By.LinkText: _by = By.LinkText(attribute); break; case Share.By.Name: _by = By.Name(attribute); break; case Share.By.PartialLinkText: _by = By.PartialLinkText(attribute); break; case Share.By.TagName: _by = By.TagName(attribute); break; case Share.By.XPath: _by = By.XPath(attribute); break; } return(_by); }