Exemple #1
0
        /// <summary>
        /// Returns the row that contains the user-specified cell text from 2 cells. This is useful for tables that can contain non-unique rows (First column cell text can bethe same)
        /// </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="additionalColCellText">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">The HTML tag name where the additionalColumnCellText exists</param>
        /// <returns></returns>
        internal static IWebElement Grid_GetRowByRowNameAndAdditionalCellName(IWebElement tblElem, By by, string firstColumnCellText, string tagNameWhereFirstColCellTextExists, string additionalColCellText, string tagNameWhereAddColCellTextExists)
        {
            IList <IWebElement> firstColumnCells      = null;
            IList <IWebElement> additionalColumnCells = null;
            IWebElement         row = null;

            string xpathString = string.Format(".//{0}[text()='{1}']", tagNameWhereFirstColCellTextExists, firstColumnCellText);

            // First wait for the table
            tblElem.WaitForElement(by, TimeSpan.FromSeconds(120), ElementCriteria.HasText, ElementCriteria.IsEnabled, ElementCriteria.IsVisible);
            Thread.Sleep(0400);

            // Now find all the cells that contain the firstColumnCellText
            firstColumnCells = tblElem.FindElements(By.XPath(xpathString));

            // Loop through each cell
            foreach (IWebElement cell in firstColumnCells)
            {
                string xpathStringAdditionalCell = string.Format(".//{0}[text()='{1}']", tagNameWhereAddColCellTextExists, additionalColCellText);

                // Get the row for the current cell in the loop
                row = XpathUtils.GetParentOrChildElemWithSpecifiedCriteria(cell, "parent", "tr[1]");

                // If we find the cell
                if (row.FindElements(By.XPath(xpathStringAdditionalCell)).Count > 0)
                {
                    additionalColumnCells = row.FindElements(By.XPath(xpathStringAdditionalCell));
                    // Return the row of this cell
                    return(row);
                }
            }

            // Mostly unreachable code, blah
            return(row);
        }
Exemple #2
0
        /// <summary>
        /// Returns the row that contains the user-specified cell
        /// </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="tagNameWhereCellTextExists">The HTML tag name where the firstColumnCellText exists</param>
        /// <returns></returns>
        public static IList <IWebElement> Grid_GetRowsByRowName(IWebElement tblElem, By rowElemby, string firstColumnCellText, string tagNameWhereCellTextExists)
        {
            // We need to instantiate this rows object, because if we dont, then when we use the Add method for this object, it will say Object
            // Reference Not Set To An Instance Of An Object. But to instantiate it, we have to use List, not iList. This is because using new()
            // means creating Objects and since IList is an interface, we can not create objects of it.
            IList <IWebElement> rows = new List <IWebElement>();

            // First wait for the table
            tblElem.WaitForElement(rowElemby, ElementCriteria.HasText, ElementCriteria.IsEnabled, ElementCriteria.IsEnabled);
            Thread.Sleep(0300);

            string xpathString = string.Format(".//{0}[text()='{1}']", tagNameWhereCellTextExists, firstColumnCellText);

            // If we find elements by using the TD tag text equals xpathstring
            if (tblElem.FindElements(By.XPath(xpathString)).Count > 0)
            {
                foreach (IWebElement cell in tblElem.FindElements(By.XPath(xpathString)))
                {
                    IWebElement nextRow = XpathUtils.GetParentOrChildElemWithSpecifiedCriteria(cell, "parent", "tr[1]");
                    rows.Add(nextRow);
                }
            }

            else
            {
                throw new Exception("The cell text for either column could not be found in the table you have specified. Either the row" +
                                    " does not exist in your table, or you made have to add an extra IF statement above for your specific table");
            }

            return(rows);
        }
        /// <summary>
        /// Returns the row that contains the user-specified cell
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="firstRowby">Send any row (Most likely just send the iwebelement that is a generic row 'tableId/tr' in the table, as it exists in your By type. i.e. Bys.CBDObserverPage,PendingAcceptanceTblRowBody). We need any row so that we can wait for it to appear before proceeding with the test"/></param>
        /// <param name="firstColumnCellText">The name of the row. i.e. The exact text from cell inside the first column</param>
        /// <param name="tagNameWhereTextExists">Inspect the text in the first row cell element and extract the tag name</param>
        /// <returns></returns>
        public static IWebElement Grid_GetRowByRowName(IWebElement tblElem, By firstRowby, string firstColumnCellText, string tagNameWhereTextExists)
        {
            IWebElement firstColumnCell = null;

            // First wait for the table
            tblElem.WaitForElement(firstRowby, TimeSpan.FromSeconds(120), ElementCriteria.HasText, ElementCriteria.IsEnabled);

            // Sometimes the text of the cell is contained within the A tag, and sometimes it is contained within the td tag, and even
            // a div tag. We are using a parameter (tagNameWhereTextExists) to handle this conditions. We will use an IF statements to
            // condition when cells have leading and trailing white space
            string xpath = string.Format(".//{0}[text()='{1}']", tagNameWhereTextExists, firstColumnCellText);
            string xpathWithExtraSpaces = string.Format(".//{0}[contains(., '{1}')]", tagNameWhereTextExists, firstColumnCellText);

            // If we find elements by using the TD tag text equals xpathstring for specific RCP table
            if (tblElem.FindElements(By.XPath(xpath)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpath))[0];
            }
            // If we find elements by using the TD tag text equals xpathstring
            else if (tblElem.FindElements(By.XPath(xpathWithExtraSpaces)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathWithExtraSpaces))[0];
            }

            else
            {
                throw new Exception("The cell text for either column could not be found in the table you have specified. Either the row");
            }

            // Then get the 1st parent row element
            IWebElement row = XpathUtils.GetParentOrChildElemWithSpecifiedCriteria(firstColumnCell, "parent", "tr[1]");

            return(row);
        }
Exemple #4
0
        /// <summary>
        /// Returns the row that contains the user-specified cell text from 2 cells. This is useful for tables that can contain non-unique rows (First column cell text can bethe same)
        /// </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="additionalCellName">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>
        /// <returns></returns>
        internal static IWebElement Grid_GetRowByRowNameAndAdditionalCellName(IWebElement tblElem, By by, string firstColumnCellText, string additionalColumnText)
        {
            IList <IWebElement> firstColumnCells      = null;
            IList <IWebElement> additionalColumnCells = null;
            IWebElement         row = null;

            // Sometimes the text of the cell is contained within the A tag, and sometimes it is contained
            // within the td tag. We will use IF statement below for this
            string xpathStringWithTDTag = string.Format(".//td[text()='{0}']", firstColumnCellText);
            string xpathStringWithATag  = string.Format(".//a[text()='{0}']", firstColumnCellText);

            // First wait for the table
            tblElem.WaitForElement(by, ElementCriteria.HasText, ElementCriteria.IsEnabled, ElementCriteria.IsVisible);
            Thread.Sleep(0400);

            // Now find all the cells that contain the firstColumnCellText:
            // If we find the cell by using the TD tag
            if (tblElem.FindElements(By.XPath(xpathStringWithTDTag)).Count > 0)
            {
                firstColumnCells = tblElem.FindElements(By.XPath(xpathStringWithTDTag));
            }
            // Else use the A tag
            else
            {
                firstColumnCells = tblElem.FindElements(By.XPath(xpathStringWithATag));
            }

            // Loop through each cell
            foreach (IWebElement cell in firstColumnCells)
            {
                // See above comment about td tag versus a tag
                string xpathStringWithTDTagAdditionalCell   = string.Format(".//td[text()='{0}']", additionalColumnText);
                string xpathStringWithATagAdditionalCell    = string.Format(".//a[text()='{0}']", additionalColumnText);
                string xpathStringWithSpanTagAdditionalCell = string.Format(".//span[text()='{0}']", additionalColumnText);

                // Get the row for the current cell in the loop
                row = XpathUtils.GetParentOrChildElemWithSpecifiedCriteria(cell, "parent", "tr[1]");

                // If we find the cell by using the TD tag
                if (row.FindElements(By.XPath(xpathStringWithTDTagAdditionalCell)).Count > 0 ||
                    row.FindElements(By.XPath(xpathStringWithATagAdditionalCell)).Count > 0 ||
                    row.FindElements(By.XPath(xpathStringWithSpanTagAdditionalCell)).Count > 0)
                {
                    additionalColumnCells = row.FindElements(By.XPath(xpathStringWithTDTagAdditionalCell));
                    // Return the row of this cell
                    return(row);
                }
            }

            // Mostly unreachable code, blah
            return(row);
        }
Exemple #5
0
        /// <summary>
        /// Returns the row that contains the user-specified cell
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="firstRowby">Send any row (Most likely just send the iwebelement that is a generic row 'tableId/tr' in the table, as it exists in your By type. i.e. Bys.CBDObserverPage,PendingAcceptanceTblRowBody). We need any row so that we can wait for it to appear before proceeding with the test"/></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>
        /// <returns></returns>
        public static IWebElement Grid_GetRowByRowName(IWebElement tblElem, By firstRowby, string firstColumnCellText, string tagNameWhereFirstColCellTextExists)
        {
            IWebElement firstColumnCell = null;

            // First wait for the table
            tblElem.WaitForElement(firstRowby, TimeSpan.FromSeconds(120), ElementCriteria.HasText, ElementCriteria.IsEnabled);
            Thread.Sleep(0400);

            // We will use IF statements to condition when cells have leading and trailing white space
            string xpathStringAllOtherTables = string.Format(".//{0}[text()='{1}']", tagNameWhereFirstColCellTextExists, firstColumnCellText);
            string xpathStringAllOtherTablesWithExtraSpaces = string.Format(".//{0}[contains(., '{1}')]", tagNameWhereFirstColCellTextExists, firstColumnCellText);

            // The first IF statement will use this xpath. This is for the Learners table in the Program Dean page of CBD. This is a weird
            // table and I had to come up with a special way to locate the cell.
            // NOTE: THE ORDER OF THE IF STATEMENTS IS CRUCIAL. DONT CHANGE THE ORDER. First RCP specific is needed. Then we need the text= before
            // the textContains because
            string xpathStringForSpecificRCPTable = string.Format("//td/a/div[@class='row']/div[contains(., '{0}')]", firstColumnCellText);

            // Specific RCP table
            if (tblElem.FindElements(By.XPath(xpathStringForSpecificRCPTable)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringForSpecificRCPTable))[0];
            }

            // All other tables (no spaces)
            else if (tblElem.FindElements(By.XPath(xpathStringAllOtherTables)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringAllOtherTables))[0];
            }

            // All other tables (leading and trailing spaces)
            else if (tblElem.FindElements(By.XPath(xpathStringAllOtherTablesWithExtraSpaces)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringAllOtherTablesWithExtraSpaces))[0];
            }

            else
            {
                throw new Exception("The cell text for either column could not be found in the table you have specified. Either the row" +
                                    " does not exist in your table, or you made have to add an extra IF statement above in this method for your specific table");
            }

            // Then get the 1st parent row element
            IWebElement row = XpathUtils.GetParentOrChildElemWithSpecifiedCriteria(firstColumnCell, "parent", "tr[1]");

            return(row);
        }
Exemple #6
0
        /// <summary>
        /// Returns the row that contains the user-specified cell
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="firstRowby">Send any row (Most likely just send the iwebelement that is a generic row 'tableId/tr' in the table, as it exists in your By type. i.e. Bys.CBDObserverPage,PendingAcceptanceTblRowBody). We need any row so that we can wait for it to appear before proceeding with the test"/></param>
        /// <param name="firstColumnCellText">The name of the row. i.e. The exact text from cell inside the first column</param>
        /// <param name="additionalCellName">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>
        /// <returns></returns>
        public static IWebElement Grid_GetRowByRowName(IWebElement tblElem, By firstRowby, string firstColumnCellText)
        {
            IWebElement firstColumnCell = null;

            // First wait for the table
            tblElem.WaitForElement(firstRowby, ElementCriteria.HasText, ElementCriteria.IsEnabled);
            Thread.Sleep(0400);

            // Sometimes the text of the cell is contained within the A tag, and sometimes it is contained
            // within the td tag, and even a div tag. We will use IF statements below for these conditions
            // We will also use IF statements to condition when cells have leading and trailing white space
            string xpathStringWithTDTag = string.Format(".//td[text()='{0}']", firstColumnCellText);
            string xpathStringWithTDTagAndExtraSpaces = string.Format(".//td[contains(., '{0}')]", firstColumnCellText);
            string xpathStringWithATag = string.Format(".//a[text()='{0}']", firstColumnCellText);
            string xpathStringWithATagAndExtraSpaces   = string.Format(".//a[contains(., '{0}')]", firstColumnCellText);
            string xpathStringWithDivTag               = string.Format(".//div[text()='{0}']", firstColumnCellText);
            string xpathStringWithDivTagAndExtraSpaces = string.Format(".//div[contains(., '{0}')]", firstColumnCellText);

            // The first IF statement will use this xpath. This is for the Learners table in the Program Dean page of CBD. This is a weird
            // table and I had to come up with a special way to locate the cell.
            // NOTE: THE ORDER OF THE IF STATEMENTS IS CRUCIAL. DONT CHANGE THE ORDER. First RCP specific is needed. Then we need the text= before
            // the textContains because
            string xpathStringForSpecificRCPTable = string.Format("//td/a/div[@class='row']/div[contains(., '{0}')]", firstColumnCellText);

            // If we find elements by using the TD tag text equals xpathstring for specific RCP table
            if (tblElem.FindElements(By.XPath(xpathStringForSpecificRCPTable)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringForSpecificRCPTable))[0];
            }
            // If we find elements by using the TD tag text equals xpathstring
            else if (tblElem.FindElements(By.XPath(xpathStringWithTDTag)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringWithTDTag))[0];
            }
            // else If we find elements by using the A tag text equals xpathstring
            else if (tblElem.FindElements(By.XPath(xpathStringWithATag)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringWithATag))[0];
            }
            // else If we find elements by using the DIV tag text equals xpathstring
            else if (tblElem.FindElements(By.XPath(xpathStringWithDivTag)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringWithDivTag))[0];
            }
            // else If we find elements by using the TD tag text contains xpathstring
            else if (tblElem.FindElements(By.XPath(xpathStringWithTDTagAndExtraSpaces)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringWithTDTagAndExtraSpaces))[0];
            }
            // else If we find elements by using the A tag text contains xpathstring
            else if (tblElem.FindElements(By.XPath(xpathStringWithATagAndExtraSpaces)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringWithATagAndExtraSpaces))[0];
            }

            else if (tblElem.FindElements(By.XPath(xpathStringWithDivTagAndExtraSpaces)).Count > 0)
            {
                firstColumnCell = tblElem.FindElements(By.XPath(xpathStringWithDivTagAndExtraSpaces))[0];
            }

            else
            {
                throw new Exception("The cell text for either column could not be found in the table you have specified. Either the row" +
                                    " does not exist in your table, or you made have to add an extra IF statement above in this method for your specific table");
            }

            // Then get the 1st parent row element
            IWebElement row = XpathUtils.GetParentOrChildElemWithSpecifiedCriteria(firstColumnCell, "parent", "tr[1]");

            return(row);
        }