Exemplo n.º 1
0
        public static SeleneElement S(string selectorValue, string selectorKind)
        {
            seleneElement = null;
            if (selectorKind != null)
            {
                switch (selectorKind)
                {
                case "css":
                    seleneElement = S(By.CssSelector(selectorValue));
                    break;

                case "xpath":
                    seleneElement = S(By.XPath(selectorValue));
                    break;

                case "text":
                    seleneElement = ExecuteScript(findByCssSelectorAndInnerText, new object[] { null, selectorValue, false }) as SeleneElement;
                    // seleneElement = S(By.XPath(String.Format("//*[contains(text(),'%s')]", selectorValue)));
                    break;

                default:
                    seleneElement = S(By.CssSelector(selectorValue));
                    break;
                }
            }
            else
            {
                seleneElement = S(By.CssSelector(selectorValue));
            }
            return(seleneElement);
        }
Exemplo n.º 2
0
        public static SeleneElement S(string selector, IWebDriver driver)
        {
            // TODO: branch
            selectorKind  = null;
            selectorValue = null;
            seleneElement = null;
            regex         = new Regex("^(?<kind>xpath|css|text) *= *(?<value>.*)$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            matches       = regex.Matches(selector);
            foreach (Match match in matches)
            {
                if (match.Length != 0)
                {
                    foreach (Capture capture in match.Groups["kind"].Captures)
                    {
                        if (selectorKind == null)
                        {
                            selectorKind = capture.ToString();
                        }
                    }
                    foreach (Capture capture in match.Groups["value"].Captures)
                    {
                        if (selectorValue == null)
                        {
                            selectorValue = capture.ToString();
                        }
                    }
                }
            }
            if (selectorKind != null)
            {
                switch (selectorKind)
                {
                case "css":
                    seleneElement = S(By.CssSelector(selectorValue), driver);
                    break;

                case "xpath":
                    seleneElement = S(By.XPath(selectorValue), driver);
                    break;

                case "text":
                    IWebElement elementToWrap = (driver as IJavaScriptExecutor).ExecuteScript(findByCssSelectorAndInnerText, new object[] { null, selectorValue }) as IWebElement;
                    seleneElement = new SeleneElement(elementToWrap, driver);
                    // seleneElement = S(By.XPath(String.Format("//*[contains(text(),'%s')]", selectorValue)), driver);
                    break;

                default:
                    seleneElement = S(By.CssSelector(selectorValue), driver);
                    break;
                }
            }
            else
            {
                seleneElement = S(By.CssSelector(selector), driver);
            }
            return(seleneElement);
        }