Question

I need to check a filter function on a table.

This filter is only on the first cell of each row and I'm trying to figure out how to get all those values...

I tried with something like

public bool CheckSearchResults(HtmlControl GridTable, string FilterTxt)
{
    List<string> Elements = new List<string>();

    foreach (HtmlCell cell in GridTable.GetChildren())
    {
        Elements.Add(cell.FilterProperties["title"]);
    }
    List<string> Results = Elements.FindAll(l => l.Contains(FilterTxt));
    return Results.Count == Elements.Count;
}

but I get stuck at the foreach loop... maybe there's a simply way with linq, but i don't know it so much


edit: all the cells i need have the same custom html tag.

with this code i should get them all, but i don't know how to iterate

HtmlDocument Document = this.UIPageWindow.UIPageDocument;
HtmlControl GridTable = this.UIPageWindow.UIPageDocument.UIPageGridTable;
HtmlCell Cells = new HtmlCell(GridTable);
Cells.FilterProperties["custom_control"] = "firstCellOfRow";

also because there's no GetEnumerator function or query models for HtmlCell objects, which are part of Microsoft.VisualStudio.TestTools.UITesting.HtmlControl library -.-


edit2: i found this article and i tried this

public bool CheckSearchResults(string FilterTxt)
{
    HtmlDocument Document = this.UIPageWindow.UIPageDocument;
    HtmlControl GridTable = this.UIPageWindow.UIPageDocument.UIPageGridTable;

    HtmlRow rows = new HtmlRow(GridTable);
    rows.SearchProperties[HtmlRow.PropertyNames.Class] = "ui-widget-content jqgrow ui-row-ltr";

    HtmlControl cells = new HtmlControl(rows);
    cells.SearchProperties["custom_control"] = "firstCellOfRow";

    UITestControlCollection collection = cells.FindMatchingControls();

    List<string> Elements = new List<string>();

    foreach (UITestControl elem in collection)
    {
        HtmlCell cell = (HtmlCell)elem;
        Elements.Add(cell.GetProperty("Title").ToString());
    }
    List<string> Results = Elements.FindAll(l => l.Contains(FilterTxt));
    return Results.Count == Elements.Count;
}

but i get an empty collection...

Was it helpful?

Solution 2

I resolved scraping pages html by myself

static public List<string> GetTdTitles(string htmlCode, string TdSearchPattern)
{
    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(htmlCode);
    HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("//td[@" + TdSearchPattern + "]");
    List<string> Results = new List<string>();
    foreach (HtmlNode node in collection)
    {
        Results.Add(node.InnerText);
    }

    return Results;
}

I'm freakin' hating those stupid coded ui test -.-

btw, thanks for the help

OTHER TIPS

Try Cell.Title or Cell.GetProperty("Title"). SearchProperties and FilterProperties are only there for searching for a UI element. They either come from the UIMap or from code if you fill them out with hand. Otherwise your code should should work.

Or you can use a LINQ query (?) like:

var FilteredElements = 
    from Cell in UIMap...GridTable.GetChildren()
    where Cell.GetProperty("Title").ToString().Contains(FilterTxt)
    select Cell;

You could also try to record a cell, add it to the UIMap, set its search or filter properties to match your filtering, then call UIMap...Cell.FindMatchingControls() and it should return all matching cells.


The problem now is that you are limiting your search for one row of the table. HtmlControl cells = new HtmlControl(rows); here the constructor parameter sets a search limit container and not the direct parent of the control. It should be the GridTable if you want to search all cells in the table. Best solution would be to use the recorder to get a cell control then modify its search and filter properties in the UIMap to match all cells you are looking for. Tho in my opinion you should stick with a hand coded filtering. Something like:

foreach(var row in GridTable.GetChildren())
{
    foreach(var cell in row.GetChildren())
    {
        //filter cell here
    }
}

Check with AccExplorer or the recorder if the hierarchy is right. You should also use debug to be sure if the loops are getting the right controls and see the properties of the cells so you will know if the filter function is right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top