Beispiel #1
0
        /// <summary>
        /// This will click on any button within a row on a table and then click the menu item that appears from that button
        /// </summary>
        /// <param name="Browser">The driver instance</param>
        /// <param name="parentElem">The parent element that contains all of the menu items within the dropdown. </param>
        /// <param name="menuItemText">The exact text from the menu item after the button is clicked</param>
        public static void Grid_ClickMenuItemInsideDropdown(IWebDriver browser, IWebElement parentElem, string menuItemText)
        {
            IWebElement menuItemElem = ElemGet.Grid_GetMenuItemOnRowButton(browser, parentElem, menuItemText);

            // We need to use javascript based clicks because IE can not click dropdown menu items in some grids (For example, the Lifetime Support grids) using
            // the Selenium based clicks
            JavascriptUtils.Click(browser, menuItemElem);
        }
        /// <summary>
        /// This will click on any button within a row on a table
        /// </summary>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="rowElemBy">Any row on your table, as it exists in your By type. We need to use this to wait for a row before we proceed with the test. i.e. Bys.CBDObserverPage,PendingAcceptanceTblBodyRow"/></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="btnText">The exact text from the button you want to click</param>
        public static IWebElement Grid_ClickButtonOrLinkWithinRow(IWebDriver browser, IWebElement tblElem, By rowElemBy, string firstColumnCellText, string additionalCellText, string btnText)
        {
            IWebElement btn = ElemGet.Grid_GetButtonOrLinkInsideRowByText(tblElem, rowElemBy, firstColumnCellText, additionalCellText, btnText);

            ElemSet.ScrollToElement(browser, btn);
            Thread.Sleep(0200);
            btn.Click();
            return(btn);
        }
Beispiel #3
0
        /// <summary>
        /// This will click on any element within a row on a table
        /// </summary>
        /// <param name="Browser">The driver instance</param>
        /// <param name="tblElem">You table element that is found within the your Page class. i.e. OP.PendingAcceptanceTbl</param>
        /// <param name="rowElemBy">Any row on your table, as it exists in your By type. We need to use this to wait for a row before we proceed with the test. i.e. Bys.CBDObserverPage,PendingAcceptanceTblBodyRow"/></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 exact text from the button you want to click</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_ClickButtonOrLinkWithinRow(IWebDriver browser, IWebElement tblElem, By rowElemBy, string firstColumnCellText, string tagNameWhereFirstColCellTextExists, string btnText, string tagNameWhereButtonExists, string additionalColCellText = null, string tagNameWhereAddColCellTextExists = null)
        {
            IWebElement btnOrLnkElem = ElemGet.Grid_GetButtonOrLinkInsideRowByText(tblElem, rowElemBy, firstColumnCellText, tagNameWhereFirstColCellTextExists, btnText, tagNameWhereButtonExists, additionalColCellText, tagNameWhereAddColCellTextExists);

            ElemSet.ScrollToElement(browser, btnOrLnkElem);
            Thread.Sleep(0200);

            btnOrLnkElem.Click();
            return(btnOrLnkElem);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// Clicks on a random check box that is contained within a "div" tag with a class attribute value of "form-group"
        /// </summary>
        /// <param name="browser">The driver instance</param>
        /// <param name="textOfChkBx">The exact text of one of the check box that you want to click</param>
        public static string ChkBx_ChooseRandom(IWebDriver browser, string textOfChkBx)
        {
            IWebElement         chkBx  = ElemGet.ChkBx_GetChkBx(browser, textOfChkBx);
            IList <IWebElement> chkBxs = ElemGet.ChkBx_GetListOfChkBxsWithinForm(chkBx);

            Random r           = new Random();
            int    randomIndex = r.Next(chkBxs.Count); //Getting a random value that is between 0 and count of items

            chkBxs[randomIndex].Click();
            return(chkBxs[randomIndex].Text);
        }
Beispiel #6
0
        /// <summary>
        /// Clicks on a random radio button within a "table" tag
        /// </summary>
        /// <param name="browser">The driver instance</param>
        /// <param name="textOfRadioBtn">The exact text of one of the radio buttons inside</param>
        public static string RdoBtn_ClickRandom(IWebDriver browser, string textOfRadioBtn)
        {
            IWebElement         rdoBtn  = ElemGet.RdoBtn_GetRdoBtn(browser, textOfRadioBtn);
            IList <IWebElement> rdoBtns = ElemGet.RdoBtn_GetRdoBtns(rdoBtn);

            Random r           = new Random();
            int    randomIndex = r.Next(rdoBtns.Count); //Getting a random value that is between 0 and (list's size)-1

            rdoBtns[randomIndex].Click();
            return(rdoBtns[randomIndex].Text);
        }
        /// <summary>
        /// This will click on any button within a row on a table and then click the menu item that appears from that 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="btnText">The exact text from the button to click, which when clicked on, results in a menu appearing</param>
        /// <param name="menuItemText">The exact text from the menu item after the button is clicked</param>
        public static void Grid_ClickMenuItemInsideButton(IWebDriver browser, IWebElement tblElem, By rowElemBy, string firstColumnCellText, string additionalCellText, string btnText, string menuItemText)
        {
            IWebElement btn = Grid_ClickButtonOrLinkWithinRow(browser, tblElem, rowElemBy, firstColumnCellText, additionalCellText, btnText);

            Thread.Sleep(0300);

            IWebElement btnParent = XpathUtils.GetNthParentElem(btn, 3);

            IWebElement menuItemElem = ElemGet.Grid_GetMenuItemOnRowButton(browser, btnParent, menuItemText);

            menuItemElem.Click();
        }
Beispiel #8
0
        /// <summary>
        /// Gets the first element in a select element containing the user specified text
        /// </summary>
        /// <param name="elem">The select element</param>
        /// <param name="textToSearchFor">The text you want to check for</param>
        /// <returns></returns>
        public static IWebElement SelElem_GetFirstItemContainingText(SelectElement elem, string textToSearchFor)
        {
            List <string> itemTextForAllItems = ElemGet.SelElem_ListTextToListString(elem);
            IWebElement   elemContainingText  = null;

            // If any of the items of the list<string> contain the text, add it to the list =
            foreach (string itemText in itemTextForAllItems)
            {
                if (itemText.Contains(textToSearchFor))
                {
                    return(elemContainingText);
                }
            }

            return(elemContainingText);
        }
Beispiel #9
0
        /// <summary>
        /// Gets the count of items in the select element containing the user specified text
        /// </summary>
        /// <param name="elem">The select element</param>
        /// <param name="textToSearchFor">The text you want to check for</param>
        /// <returns></returns>
        public static int SelElem_GetCountOfItemsContainingText(SelectElement elem, string textToSearchFor)
        {
            List <string> itemTextForAllItems = ElemGet.SelElem_ListTextToListString(elem);
            int           countOfItems        = 0;

            // If any of the items of the list<string> contain the text, add it to the list =
            foreach (string itemText in itemTextForAllItems)
            {
                if (itemText.Contains(textToSearchFor))
                {
                    countOfItems++;
                }
            }

            return(countOfItems);
        }
Beispiel #10
0
        /// <summary>
        /// If any of the items in the select element contain the user specified text, return true, else return false
        /// </summary>
        /// <param name="elem">The select element</param>
        /// <param name="textToSearchFor">The text you want to verify exists in the select element</param>
        /// <returns></returns>
        public static bool SelElem_ContainsText(SelectElement elem, string textToSearchFor)
        {
            List <string> itemTextForAllItems = ElemGet.SelElem_ListTextToListString(elem);

            // If any of the items of the list<string> contain the text , return true
            foreach (string itemText in itemTextForAllItems)
            {
                if (itemText.Contains(textToSearchFor))

                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// Selects the first indexed item in the dropdown that contains the user-specified text
        /// </summary>
        /// <param name="elem">The element</param>
        /// <param name="text">The text to search for</param>
        /// <returns></returns>
        public static string SelElem_SelectItemContainingText(SelectElement elem, string text)
        {
            List <string> itemStrings    = ElemGet.SelElem_ListTextToListString(elem);
            string        selectedString = "";

            // For each item's string in the dropdown
            foreach (string itemString in itemStrings)
            {
                // If the string contains the user-specified text, then select it
                if (itemString.Contains(text))
                {
                    elem.SelectByText(itemString);
                    selectedString = itemString;
                    break;
                }
            }

            return(selectedString);
        }
Beispiel #12
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);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        /// <summary>
        /// Clicks a radio button of your choice
        /// </summary>
        /// <param name="browser">The driver instance</param>
        /// <param name="textOfRadioBtn">The exact text as it appears in the HTML of the radio button to click</param>
        /// <returns></returns>
        public static string RdoBtn_ClickByText(IWebDriver browser, string textOfRadioBtn)
        {
            // Right now I have to implement the below IF statement for radio buttons, as their tags are different
            // between learners and observers. Nirav is going to fix this. Once he does, I can implement the simpler solution
            string xpathString = string.Format("//label/span[text()='{0}']", textOfRadioBtn);

            //Thread.Sleep(3000);

            if (browser.FindElements(By.XPath(xpathString)).Count > 0)
            {
                IWebElement rdoBtn       = ElemGet.RdoBtn_GetRdoBtn(browser, textOfRadioBtn);
                IWebElement rdoBtnParent = XpathUtils.GetNthParentElem(rdoBtn, 1);
                rdoBtnParent.Click();
                return(textOfRadioBtn);
            }
            else
            {
                IWebElement rdoBtn = ElemGet.RdoBtn_GetRdoBtn(browser, textOfRadioBtn);
                rdoBtn.Click();
                return(textOfRadioBtn);
            }
        }
Beispiel #15
0
        /// <summary>
        /// This will select an item inside of a select element within a row of a grid
        /// </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="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>
        /// <param name="itemToChoose">The exact text of the item you want to choose</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 void Grid_SelectItemWithinSelElem(IWebElement tblElem, By by, string firstColumnCellText, string tagNameWhereFirstColCellTextExists, string idOfSelElem, string itemToChoose, string additionalColCellText = null, string tagNameWhereAddColCellTextExists = null)
        {
            SelectElement selElem = ElemGet.Grid_GetSelElemInsideRowByID(tblElem, by, firstColumnCellText, tagNameWhereFirstColCellTextExists, idOfSelElem, additionalColCellText, tagNameWhereAddColCellTextExists);

            selElem.SelectByText(itemToChoose);
        }
        /// <summary>
        /// This will select an item inside of a select element within a row of a grid
        /// </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>
        /// <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>
        /// <param name="itemToChoose">The exact text of the item you want to choose</param>
        public static void Grid_SelectItemWithinSelElem(IWebElement tblElem, By by, string firstColumnCellText, string additionalCellText, string idOfSelElem, string itemToChoose)
        {
            SelectElement selElem = ElemGet.Grid_GetSelElemInsideRowByID(tblElem, by, firstColumnCellText, additionalCellText, idOfSelElem);

            selElem.SelectByText(itemToChoose);
        }