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 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 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 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 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")); }
private static IHtmlElement TryFindElementByDescriptor(IHtmlDocument document, PathCellDescriptor descriptor) { if (string.IsNullOrEmpty(descriptor.Path)) { return(null); } var table = HtmlTable.GetByPath(document, HtmlPath.Parse(descriptor.Path)); if (table == null) { return(null); } int rowToScan = descriptor.Column.HeaderSeriesPosition; if (0 > rowToScan || rowToScan >= table.Rows.Count) { return(null); } var colIdx = descriptor.Column.FindIndex(table.GetRow(rowToScan).Select(item => item.InnerText)); if (colIdx == -1) { return(null); } var colToScan = descriptor.Row.HeaderSeriesPosition; if (0 > colToScan || colToScan >= table.GetRow(0).Count()) { return(null); } var rowIdx = descriptor.Row.FindIndex(table.GetColumn(colToScan).Select(item => item.InnerText)); if (rowIdx == -1) { return(null); } return(table.GetCell(rowIdx, colIdx)); }
private static IHtmlElement TryFindElementByDescriptor(IHtmlDocument document, PathSeriesDescriptor descriptor) { if (string.IsNullOrEmpty(descriptor.Path)) { return(null); } var table = HtmlTable.GetByPath(document, HtmlPath.Parse(descriptor.Path)); if (table == null) { return(null); } if (descriptor.Orientation == SeriesOrientation.Column) { int rowToScan = descriptor.ValuesLocator.HeaderSeriesPosition; if (0 > rowToScan || rowToScan >= table.Rows.Count) { return(null); } var colIdx = descriptor.ValuesLocator.FindIndex(table.GetRow(rowToScan).Select(item => item.InnerText)); if (colIdx == -1) { return(null); } int rowIdx = 0; if (rowIdx == descriptor.ValuesLocator.HeaderSeriesPosition && rowIdx < table.Rows.Count) { rowIdx++; } return(table.GetCell(rowIdx, colIdx)); } else if (descriptor.Orientation == SeriesOrientation.Row) { var colToScan = descriptor.ValuesLocator.HeaderSeriesPosition; if (0 > colToScan || colToScan >= table.GetRow(0).Count()) { return(null); } var rowIdx = descriptor.ValuesLocator.FindIndex(table.GetColumn(colToScan).Select(item => item.InnerText)); if (rowIdx == -1) { return(null); } int colIdx = 0; if (colIdx == descriptor.ValuesLocator.HeaderSeriesPosition && colIdx < table.GetRow(rowIdx).Count) { colIdx++; } return(table.GetCell(rowIdx, colIdx)); } throw new NotSupportedException("Unknown orientation: " + descriptor.Orientation); }