Ejemplo n.º 1
0
        /// <summary>
        /// Gets the user-specified button element within a table by the text value of the button
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="rowElemBy">Your row element as it exists in your By type. i.e. Bys.CBDObserverPage,PendingAcceptanceTblRowBody"/></param>
        /// <param name="firstColumnCellText">The name of the row. i.e. The exact text from cell inside the first column</param>
        /// <param name="additionalCellText">Send "null" to this parameter if your table does not allow duplicate rows for the first column. If the first column in your row does not have to be unique compared to other rows in your table, and you would want to specify an additional column value to find your row, you can do that here. Send the exact text of any other column.</param>
        /// <param name="buttonText">The exact text from the button you want/param>
        public static IWebElement Grid_GetButtonOrLinkInsideRowByText(IWebElement tblElem, By rowElemBy, string firstColumnCellText, string additionalCellText, string btnText)
        {
            IWebElement row     = null;
            IWebElement btnLink = null;

            // Get the row element
            if (additionalCellText == null)
            {
                row = ElemGet.Grid_GetRowByRowName(tblElem, rowElemBy, firstColumnCellText);
            }
            else
            {
                row = ElemGet.Grid_GetRowByRowNameAndAdditionalCellName(tblElem, rowElemBy, firstColumnCellText, additionalCellText);
            }

            // Get the button element with the user-specified text and click on it
            string textOfButtonWithoutSpaces = btnText.Replace(" ", "");


            // Sometimes the text of the cell is contained within the span tag, and sometimes it is contained
            // within the button or A tag. Sometimes additional attributes are needed to find the button. We will
            // use IF statements below for these conditions.
            string xpathStringForFirstTypeOfButton  = string.Format(".//span[text()='{0}' and @data-i18n='_{1}_']", btnText, textOfButtonWithoutSpaces);
            string xpathStringForSecondTypeOfButton = string.Format(".//span[text()='{0}' and @role='button']", btnText);
            string xpathStringForThirdTypeOfButton  = string.Format(".//button[text()='{0}']", btnText);
            string xpathStringFor4thTypeOfButton    = string.Format(".//a[text()='{0}']", btnText);
            string xpathStringFor5thTypeOfButton    = string.Format(".//span[text()='{0}']", btnText);

            if (row.FindElements(By.XPath(xpathStringForFirstTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringForFirstTypeOfButton));
            }
            else if (row.FindElements(By.XPath(xpathStringForSecondTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringForSecondTypeOfButton));
            }
            else if (row.FindElements(By.XPath(xpathStringForThirdTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringForThirdTypeOfButton));
            }
            else if (row.FindElements(By.XPath(xpathStringFor4thTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringFor4thTypeOfButton));
            }
            else if (row.FindElements(By.XPath(xpathStringFor5thTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringFor5thTypeOfButton));
            }
            else
            {
                throw new Exception("The button/link could not be found in the table you have specified with the celltext you specified");
            }

            return(btnLink);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the user-specified element within a table by the user-specified cell text of your user-specified row
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="by">Your row element as it exists in your By type. i.e. Bys.CBDObserverPage,PendingAcceptanceTblRowBody"/></param>
        /// <param name="firstColumnCellText">The name of the row. i.e. The exact text from cell inside the first column</param>
        /// <param name="tagNameWhereFirstColCellTextExists">The HTML tag name where the firstColumnCellText exists</param>
        /// <param name="btnText">The text of the button you want to click on</param>
        /// <param name="tagNameWhereButtonExists">The HTML tag name where the firstColumnCellText exists</param>
        /// <param name="additionalColCellText">(Optional) If the first column in your row does not have to be unique compared to other rows in your table, and you would want to specify an additional column value to find your row, you can do that here. Send the exact text of any other column.</param>
        /// <param name="tagNameWhereAddColCellTextExists">(Optional) The HTML tag name where the additionalColumnCellText exists</param>
        public static IWebElement Grid_GetButtonOrLinkInsideRowByText(IWebElement tblElem, By rowElemBy, string firstColumnCellText, string tagNameWhereFirstColCellTextExists, string btnText, string tagNameWhereButtonTextExists, string additionalColCellText = null, string tagNameWhereAddColCellTextExists = null)
        {
            IWebElement row     = null;
            IWebElement btnLink = null;

            // Get the row element
            if (additionalColCellText.IsNullOrEmpty())
            {
                row = ElemGet.Grid_GetRowByRowName(tblElem, rowElemBy, firstColumnCellText, tagNameWhereFirstColCellTextExists);
            }
            else
            {
                row = ElemGet.Grid_GetRowByRowNameAndAdditionalCellName(tblElem, rowElemBy, firstColumnCellText, tagNameWhereFirstColCellTextExists, additionalColCellText, tagNameWhereAddColCellTextExists);
            }

            // Get the button element with the user-specified text and click on it
            string textOfButtonWithoutSpaces = btnText.Replace(" ", "");

            // Sometimes the button includes leading and trailing whitespace. Sometimes additional attributes are needed to find the
            // button. We will use IF statements below for these conditions.
            string xpathStringForFirstTypeOfButton  = string.Format(".//{0}[text()='{1}' and @data-i18n='_{2}_']", tagNameWhereButtonTextExists, btnText, textOfButtonWithoutSpaces);
            string xpathStringForSecondTypeOfButton = string.Format(".//{0}[text()='{1}' and @role='button']", tagNameWhereButtonTextExists, btnText);
            string xpathStringForThirdTypeOfButton  = string.Format(".//{0}[text()='{1}']", tagNameWhereButtonTextExists, btnText);

            if (row.FindElements(By.XPath(xpathStringForFirstTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringForFirstTypeOfButton));
            }
            else if (row.FindElements(By.XPath(xpathStringForSecondTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringForSecondTypeOfButton));
            }
            else if (row.FindElements(By.XPath(xpathStringForThirdTypeOfButton)).Count > 0)
            {
                btnLink = row.FindElement(By.XPath(xpathStringForThirdTypeOfButton));
            }
            else
            {
                throw new Exception("The button/link could not be found in the table you have specified with the celltext you specified");
            }

            return(btnLink);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the user-specified Select Element within a table by the ID of the Select Element
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="by">Your row element as it exists in your By type. i.e. Bys.CBDObserverPage,PendingAcceptanceTblRowBody"/></param>
        /// <param name="firstColumnCellText">The name of the row. i.e. The exact text from cell inside the first column</param>
        /// <param name="additionalCellText">Send "null" to this parameter if your table does not allow duplicate rows for the first column. If the first column in your row does not have to be unique compared to other rows in your table, and you would want to specify an additional column value to find your row, you can do that here. Send the exact text of any other column.</param>
        /// <param name="idOfSelElem">The exact text of the ID of the Select Element, however, if your select element is dynamically numbered per row, then only send the text before the number. For example, is the select tag has an ID of "Priority_0", only send "Priority"</param>
        public static SelectElement Grid_GetSelElemInsideRowByID(IWebElement tblElem, By by, string firstColumnCellText, string additionalCellText, string idOfSelElem)
        {
            IWebElement row = null;

            // Get the row element
            if (additionalCellText == null)
            {
                row = ElemGet.Grid_GetRowByRowName(tblElem, by, firstColumnCellText);
            }
            else
            {
                row = ElemGet.Grid_GetRowByRowNameAndAdditionalCellName(tblElem, by, firstColumnCellText, additionalCellText);
            }

            SelectElement selElem = new SelectElement(row.FindElement(By.XPath(string.Format(".//select[contains(@id, '{0}')]", idOfSelElem))));

            // //a[text()='_TA_AStatic User_LR_CH_001']/ancestor::tr[1]//select[contains(@id, 'ReviewStatus')]

            return(selElem);
        }