public void When_css_class_contains_no_alpha_numerics()
        {
            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize("span.loginbox");

            Assert.AreEqual(3, tokens.Length);

            tokens = tokenizer.Tokenize("span.login-box");

            Assert.AreEqual(3, tokens.Length);
        }
Beispiel #2
0
        public static IEnumerable <HtmlNode> CssSelect(this HtmlNode node, string expression)
        {
            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize(expression);
            var executor  = new CssSelectorExecutor <HtmlNode>(new List <HtmlNode> {
                node
            }, tokens.ToList(), new AgilityNavigationProvider());

            return(executor.GetElements());
        }
        public void When_execute_css_selector2()
        {
            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize("div.widget.monthlist");

            Assert.AreEqual(5, tokens.Length);

            var executor = new CssSelectorExecutor <HtmlNode>(html.ChildNodes.ToList(), tokens.ToList(), new AgilityNavigationProvider());

            HtmlNode[] htmlNodes = executor.GetElements();

            Assert.AreEqual(1, htmlNodes.Length);
        }
        public static IEnumerable <HElement> CssSelect(this HElement node, string expression)
        {
            if (string.IsNullOrEmpty(expression))
            {
                return new HElement[] { }
            }
            ;

            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize(expression);
            var executor  = new CssSelectorExecutor <HElement>(new List <HElement> {
                node
            }, tokens.ToList(), new HElementNavigationProvider());

            return(executor.GetElements());
        }
    }
        public void When_tokenize_selectors_used_in_v1()
        {
            var tokenizer = new CssSelectorTokenizer();
            var tokens    = tokenizer.Tokenize("span.loginbox");

            Assert.AreEqual(3, tokens.Length);

            tokens = tokenizer.Tokenize("span.login-box");
            Assert.AreEqual(3, tokens.Length);

            tokens = tokenizer.Tokenize("script[type=text/javascript]");
            Assert.AreEqual(6, tokens.Length);

            tokens = tokenizer.Tokenize("hr[id^=bla]");
            Assert.AreEqual(6, tokens.Length);

            tokens = tokenizer.Tokenize("hr[id$=ing]");
            Assert.AreEqual(6, tokens.Length);

            tokens = tokenizer.Tokenize("link[type=application/rdf+xml]");
            Assert.AreEqual(6, tokens.Length);
        }