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)); }
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]")); }
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()); }
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()); }
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)); }
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")); }
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); }
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); }
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); }
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")); }
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); }
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" })); }
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)); }
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); }
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"))); }
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"))); }
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()); }
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)); }
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)); }
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)); }
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)); }
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()); }
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); }
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); }
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); }
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); }