コード例 #1
0
        public bool selectByOptionText(By locator, string value, string locatorName)
        {
            bool flag = false;

            try
            {
                WebElement ListBox = driver.FindElement(locator);
                IReadOnlyCollection <WebElement> options = ListBox.FindElements(By.TagName("option"));
                foreach (var option in options)
                {
                    string opt = option.Text.Trim();
                    if (opt.ToLower().Equals(value.ToLower().Trim()))
                    {
                        option.Click();
                        flag = true;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(Path.Combine(projectLoc, TestContext.CurrentContext.Test.Name + "-" + DateTime.Now.ToString("dd-M-yyyy", CultureInfo.InvariantCulture) + "." + format), ScreenshotImageFormat.Jpeg);
                throw new Exception("Option with value attribute " + value + " is Not Select from the DropDown " + locatorName + " " + e.Message);
            }
            return(flag);
        }
コード例 #2
0
ファイル: ActionEngine.cs プロジェクト: purna1221/Microsite
        public bool selectByOptionText(By locator, string value, string locatorName)
        {
            bool flag = false;

            try
            {
                WebElement ListBox = driver.FindElement(locator);
                ReadOnlyCollection <WebElement> options = ListBox.FindElements(By.TagName("option"));
                foreach (var option in options)
                {
                    string opt = option.Text.Trim();
                    if (opt.ToLower().Equals(value.ToLower().Trim()))
                    {
                        option.Click();
                        flag = true;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                TakeScreenShot();
                throw new Exception("Option with value attribute " + value + " is Not Select from the DropDown " + locatorName + " " + e.Message);
            }
            return(flag);
        }
コード例 #3
0
 private WebElementCollection findElements(OpenQA.Selenium.By by, int timeoutms)
 {
     try {
         if (timeoutms < 1)
         {
             return(new WebElementCollection(this._wd, _webElement.FindElements(by)));
         }
         return(new WebElementCollection(this._wd, this._wd.WaitNotNullOrTrue(() => {
             var elts = _webElement.FindElements(by);
             return elts.Count == 0 ? null : elts;
         }, timeoutms)));
     } catch (Exception ex) {
         if (ex is NoSuchElementException || ex is TimeoutException)
         {
             throw new Exception("Elements not found. " + "Method=" + by.ToString().ToLower().Substring(3).Replace(": ", ", value="));
         }
         throw;
     }
 }
コード例 #4
0
        public bool ClickById(string name, OpenQA.Selenium.IWebElement parentElement = null, int index = 0, int sleep = 0, string checkString = "||||||||||||||||")
        {
            var el = parentElement != null?parentElement.FindElements(By.Id(name)) : Driver.FindElementsById(name);

            if (el.Count == 0)
            {
                return(false);
            }
            el.ElementAt(index).Click();
            return(IsBrowserReady(sleep, checkString));
        }
コード例 #5
0
        protected bool findResultElement()
        {
            string message = string.Empty;
            string oldUrl  = _WebDriver.Url;

            string containerDIVClassName = "container";

            QA.IWebElement containerElement = FindElementByClassName(containerDIVClassName);
            if (containerElement == null)
            {
                message = string.Format("Not found element <{0}>.", containerDIVClassName);
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(false);
            }

            IList <QA.IWebElement> webElements = containerElement.FindElements(QA.By.TagName("span"));

            foreach (QA.IWebElement webElement in webElements)
            {
                _SystemLog.writeLog2Console(LOG_LEVEL.DEBUG, string.Format("Element<{0}><{1}>.", webElement.TagName, webElement.Text));
            }

            return(true);
        }