Exemplo n.º 1
0
        public void Rows_WhenCalled_AllTRElementsReturned()
        {
            var doc   = HtmlDocumentLoader.LoadHtml(GetHtml());
            var table = HtmlTable.GetByPath(doc, HtmlPath.Parse("/BODY[0]/TABLE[0]"));

            Assert.That(table.Rows.Count, Is.EqualTo(4));
        }
Exemplo n.º 2
0
        private void Apply()
        {
            Marker.Unmark();

            if (Document == null)
            {
                return;
            }

            if (mySelectedElement == null && myPath != null)
            {
                var path = HtmlPath.TryParse(myPath);
                if (path != null)
                {
                    // Trigger SelectionChanged event
                    SelectedElement = ( HtmlElementAdapter )Document.GetElementByPath(path);
                }
            }
            else if (mySelectedElement != null && myPath == null)
            {
                // do NOT set property - it will reset SelectedElement again (StackOverflowException)
                myPath = mySelectedElement.GetPath().ToString();
            }

            if (mySelectedElement == null || mySelectedElement.TagName.Equals("INPUT", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            Marker.Mark(mySelectedElement);

            mySelectedElement.Element.ScrollIntoView(false);
        }
Exemplo n.º 3
0
        public void GetPathToTable_PathToTable_ReturnsPathToTableElement()
        {
            var path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]");

            var pathToTable = path.GetPathToTable();

            Assert.That(pathToTable.ToString(), Is.EqualTo("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]"));
        }
Exemplo n.º 4
0
        private static StyleMap DefaultStyleMap()
        {
            return(StyleMap.builder()

                   .mapParagraph(ParagraphMatcher.styleName("Normal"), HtmlPath.element("p"))

                   .build());
        }
Exemplo n.º 5
0
        public void GetPath()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");

            var e = myDocument.GetElementByPath(path);

            Assert.AreEqual(path.ToString(), e.GetPath().ToString());
        }
Exemplo n.º 6
0
        public void GetChildPosRoot()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");

            var e = myDocument.GetElementByPath(path);

            Assert.AreEqual(0, e.GetRoot().GetChildPos());
        }
Exemplo n.º 7
0
        public void GetCellAt()
        {
            HtmlPath  path  = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");
            var       e     = myDocument.GetElementByPath(path);
            HtmlTable table = myDocument.GetTableByPath(path);

            Assert.AreEqual(e, table.GetCellAt(6, 1));
        }
Exemplo n.º 8
0
        public void ColumnIndexOf_WithCell_ReturnsCorrectIndex()
        {
            var doc   = HtmlDocumentLoader.LoadHtml(GetHtml());
            var table = HtmlTable.GetByPath(doc, HtmlPath.Parse("/BODY[0]/TABLE[0]"));

            var idx = table.ColumnIndexOf(doc.GetElementById("c12"));

            Assert.That(idx, Is.EqualTo(2));
        }
Exemplo n.º 9
0
        public void FindParent()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");

            var element = myDocument.GetElementByPath(path);
            var table   = element.FindParent(e => e.TagName == "TABLE");

            Assert.AreEqual("TABLE", table.TagName);
        }
Exemplo n.º 10
0
        public void GetRoot()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");

            var e = myDocument.GetElementByPath(path);

            Assert.AreEqual("TD", e.TagName);
            Assert.AreEqual("HTML", e.GetRoot().TagName);
        }
Exemplo n.º 11
0
        public void PathParse()
        {
            HtmlPath p = HtmlPath.Parse("/TABLE[0]/TR[2]/TD[4]");

            Assert.AreEqual(3, p.Elements.Count);
            Assert.IsTrue(p.PointsToTableCell);
            Assert.IsFalse(p.PointsToTable);
            Assert.AreEqual("TD", p.Last.TagName);
        }
Exemplo n.º 12
0
        public void GetChildAt()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]");

            var e = myDocument.GetElementByPath(path);

            Assert.AreEqual("2,78", e.GetChildAt("td", 1).InnerText);
            Assert.AreEqual("3,00", e.GetChildAt("td", 2).InnerText);
        }
Exemplo n.º 13
0
        public void GetRow_WithCell_ReturnsCorrectTDs()
        {
            var doc   = HtmlDocumentLoader.LoadHtml(GetHtml());
            var table = HtmlTable.GetByPath(doc, HtmlPath.Parse("/BODY[0]/TABLE[0]"));

            var row = table.GetRow(doc.GetElementById("c12"));

            Assert.That(row[0].Parent.Id, Is.EqualTo("row1"));
        }
Exemplo n.º 14
0
        public void GetCell_WithRowAndColumn_ReturnsCorrectCell()
        {
            var doc   = HtmlDocumentLoader.LoadHtml(GetHtml());
            var table = HtmlTable.GetByPath(doc, HtmlPath.Parse("/BODY[0]/TABLE[0]"));

            var element = table.GetCell(1, 2);

            Assert.That(element.Id, Is.EqualTo("c12"));
        }
Exemplo n.º 15
0
        public void GetColumn_WithCell_ReturnsCorrectTDs()
        {
            var doc   = HtmlDocumentLoader.LoadHtml(GetHtml());
            var table = HtmlTable.GetByPath(doc, HtmlPath.Parse("/BODY[0]/TABLE[0]"));

            var column = table.GetColumn(doc.GetElementById("c12"));

            Assert.That(column.Select(td => td.Id), Is.EquivalentTo(new[] { "c02", "c12", "c22", "c32" }));
        }
Exemplo n.º 16
0
        public void First()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]");

            var element = myDocument.GetElementByPath(path);
            var body    = element.Children.FirstOrDefault(e => e.TagName == "TBODY");

            Assert.AreEqual("TBODY", body.TagName);
        }
Exemplo n.º 17
0
        public void FindEmbeddingTableNoTable()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]");

            var       element = myDocument.GetElementByPath(path);
            HtmlTable table   = element.FindEmbeddingTable();

            Assert.IsNull(table);
        }
Exemplo n.º 18
0
        public void GetRow()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");
            var      e    = myDocument.GetElementByPath(path);

            var row = HtmlTable.GetRow(e);

            Assert.AreEqual(7, row.Count());
            Assert.AreEqual(e, row.ElementAt(1));
        }
Exemplo n.º 19
0
        public void GetTextByPath_SimplePath()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[0]/DIV[1]");

            var    doc   = LoadDocument("ariva.html");
            var    e     = doc.GetElementByPath(path);
            string value = doc.GetTextByPath(path);

            Assert.AreEqual("Willkommen, Gast!", value);
        }
Exemplo n.º 20
0
        public void GetElementByPath_NoElementWithSuchPath_ReturnsNull()
        {
            var doc = HtmlDocumentLoader.LoadHtml("<html><body><div id='xx'/></body></html>");

            var path = HtmlPath.Parse("/html[0]/BODY[0]/P[0]");

            var element = doc.GetElementByPath(path);

            Assert.That(element, Is.Null);
        }
Exemplo n.º 21
0
        public void GetElementByPath_MultipleElementsWithSameTagName_ElementFound()
        {
            var doc = HtmlDocumentLoader.LoadHtml("<html><body><div/><div/><div><P/><P/><p id='xx'/></div></body></html>");

            var path = HtmlPath.Parse("/BODY[0]/div[2]/P[2]");

            var element = doc.GetElementByPath(path);

            Assert.That(element, Is.EqualTo(doc.GetElementById("xx")));
        }
Exemplo n.º 22
0
        public void Creation()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");

            HtmlTable table = myDocument.GetTableByPath(path);

            Assert.AreEqual("TABLE", table.TableElement.TagName);
            Assert.AreEqual("TBODY", table.TableBody.TagName);
            Assert.AreEqual(9, table.Rows.Count());
        }
Exemplo n.º 23
0
        public void FirstComplex()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]");

            var element = myDocument.GetElementByPath(path);
            var first   = element.Children.FirstOrDefault(e => e.TagName == "TD" && e.InnerText == "3,00");

            Assert.AreEqual("TD", first.TagName);
            Assert.AreEqual("3,00", first.InnerText);
        }
Exemplo n.º 24
0
        public void GetIndices()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");
            var      e    = myDocument.GetElementByPath(path);

            Assert.AreEqual(1, HtmlTable.GetColumnIndex(e));
            Assert.AreEqual(6, HtmlTable.GetRowIndex(e));
            Assert.AreEqual(e, HtmlTable.GetEmbeddingTD(e));
            Assert.AreEqual(e.Parent, HtmlTable.GetEmbeddingTR(e));
        }
Exemplo n.º 25
0
        public void GetElementByPath_PathPointsToBody_BodyReturned()
        {
            var doc = HtmlDocumentLoader.LoadHtml("<html><body></body></html>");

            var path = HtmlPath.Parse("/body[0]");

            var element = doc.GetElementByPath(path);

            Assert.That(element, Is.EqualTo(doc.Body));
        }
Exemplo n.º 26
0
        public void GetElementByPath_SimplePath_ElementFound()
        {
            var doc = HtmlDocumentLoader.LoadHtml("<html><body><div id='xx'/></body></html>");

            var path = HtmlPath.Parse("/BODY[0]/div[0]");

            var element = doc.GetElementByPath(path);

            Assert.That(element, Is.EqualTo(doc.GetElementById("xx")));
        }
Exemplo n.º 27
0
        public void GetElementByPath()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");
            var      doc  = LoadDocument("ariva.html");
            var      e    = doc.GetElementByPath(path);

            Assert.AreEqual("TD", e.TagName);
            Assert.AreEqual("TR", e.Parent.TagName);
            Assert.AreEqual(1, e.GetChildPos());
            Assert.AreEqual(6, e.Parent.GetChildPos());
        }
Exemplo n.º 28
0
        public void GetColumn()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");
            var      e    = myDocument.GetElementByPath(path);

            var column = HtmlTable.GetColumn(e);

            // Hint: colspan not implemented
            Assert.AreEqual(8, column.Count());
            Assert.AreEqual(e, column.ElementAt(5));
        }
Exemplo n.º 29
0
        public void GetTextByPath()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]/TR[6]/TD[1]");

            var    doc   = LoadDocument("ariva.html");
            var    e     = doc.GetElementByPath(path);
            string value = doc.GetTextByPath(path);

            Assert.AreEqual(e.InnerText, value);
            Assert.AreEqual("2,78", value);
        }
Exemplo n.º 30
0
        public void FindParentWithAbort()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/CENTER[0]/TABLE[0]/TBODY[0]/TR[0]/TD[0]");

            var element = myDocument.GetElementByPath(path);
            // dont leave the table
            var x = element.FindParent(e => e.TagName == "CENTER", e => e.TagName == "TABLE");

            // if the abort condition fails "x" would not be null
            Assert.IsNull(x);
        }