示例#1
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);
        }
示例#2
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);
            }
        }