Beispiel #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));
        }
Beispiel #2
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]"));
        }
Beispiel #3
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());
        }
Beispiel #4
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());
        }
Beispiel #5
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));
        }
Beispiel #6
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"));
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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"));
        }
Beispiel #11
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);
        }
Beispiel #12
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" }));
        }
Beispiel #13
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));
        }
Beispiel #14
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);
        }
Beispiel #15
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);
        }
        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);
        }
        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")));
        }
Beispiel #18
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);
        }
        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")));
        }
Beispiel #20
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());
        }
Beispiel #21
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));
        }
Beispiel #22
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));
        }
Beispiel #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);
        }
        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));
        }
Beispiel #25
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));
        }
Beispiel #26
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());
        }
Beispiel #27
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);
        }
Beispiel #28
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);
        }
Beispiel #29
0
        public void GetTableByPath()
        {
            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);

            e = e.Parent.Parent.Parent;
            HtmlTable table = doc.GetTableByPath(path);

            Assert.AreEqual(e, table.TableElement);
            Assert.AreEqual(e.Children.First(), table.TableBody);
        }
Beispiel #30
0
        public void FindEmbeddingTableSelfEmbedded()
        {
            HtmlPath path = HtmlPath.Parse("/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]");

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

            Assert.IsNotNull(table);

            table = element.Parent.FindEmbeddingTable();

            Assert.IsNotNull(table);
            Assert.AreEqual(element.Parent, table.TableElement);
        }