Possible HtmlFindExpression bug

3 posts, 1 answers
  1. Martin
    Martin avatar
    51 posts
    Member since:
    Dec 2011

    Posted 21 May 2012 Link to this post


    I think I have found a bug in the HtmlFindExpressions either that or I have stared my self completely blind on a obvious problem and in any case i need somebody to review and help :)

    I have a HtmlFindExpression that I belive should do the same as a XPATH I have created, the problem is that my XPATH works but my HtmlFindExpression only find 1 item(Expected 10). I have created some test code below and put some areas around the blocks.

    Explation of areas:
    Finding elements with xpath which works as expected
    Problem: none

    Finding elements with pure HtmlFindExpression.
    Problem: Finds 1 element instead of 10

    Attempting to find the element by putting xpath inside a HtmlFindExpression.
    Problem: Telerik throws error that it doesn't support hierarchal dependency in HtmlFindExpressions, but there isn't a hierarchal dependency in this xpath.

    NOTE: Added a screenshot of the result i get.

    Thread.Sleep(10000); // Didn't bother with a real wait.
    // Expected count is 10
    // Area1
    // Test with XPATH: This seems to work
    Console.WriteLine("AREA1 ** START **");
    string xpath = "//li[contains(@class,'postItem') and @data-url]";
    ReadOnlyCollection<Element> collection = ActiveBrowser.Find.AllByXPath(xpath);
    Console.WriteLine("XPATH find all as element count: " + collection.Count);
    ReadOnlyCollection<HtmlListItem> collection1 = ActiveBrowser.Find.AllByXPath<HtmlListItem>(xpath);
    Console.WriteLine("XPATH find all as HtmlListItem count: " + collection1.Count);
    Console.WriteLine("AREA1 ** END **");
    // Area2
    // Test with HtmlFindExpression: This finds nothing
    Console.WriteLine("AREA2 ** Start **");
    HtmlFindExpression findExp = new HtmlFindExpression("tagname=li", "class=~postItem", "innermarkup=~data-url");
    ReadOnlyCollection<Element> collection4 = ActiveBrowser.Find.AllByExpression(findExp);
    Console.WriteLine("HtmlFindExpression find all as element count: " + collection4.Count);
    ReadOnlyCollection<HtmlListItem> collection5 = ActiveBrowser.Find.AllByExpression<HtmlListItem>(findExp);
    Console.WriteLine("HtmlFindExpression find all as HtmlListItem count: " + collection5.Count);
    Console.WriteLine("AREA2 ** END **");
    // Area3
    // Test with XPATH inside HtmlFindExpression: This is misinterpreted
    Console.WriteLine("AREA3 ** Start **");
    HtmlFindExpression findExp1 = new HtmlFindExpression("xpath=//li[contains(@class,'postItem') and @data-url]");
    ReadOnlyCollection<Element> collection2 = ActiveBrowser.Find.AllByExpression(findExp1);
    ReadOnlyCollection<HtmlListItem> collection3 = ActiveBrowser.Find.AllByExpression<HtmlListItem>(findExp1);
    Console.WriteLine("AREA3 ** END **");
  2. Answer
    Anthony avatar
    19 posts

    Posted 24 May 2012 Link to this post

    Hello Martin,

    Thank you for the code and sample site.

    Area 2
    The Find Expression is using InnerMarkup. InnerMarkup returns the text content from the selected node, plus all markup in the selected node's children. You don’t get the selected node’s markup — only its text. You’ll get full markup for everything below the selected text.

    I changed it to OuterMarkup and it correctly returned 10 elements:

    HtmlFindExpression findExp = new HtmlFindExpression("tagname=li", "class=~postItem", "outermarkup=~data-url");

    See here for more information on validation content element types.

    Area 3
    We're not sure why this isn't working as expected. I filed a bug on that error and you can find the PITS Issue here: Public URL. In the meantime just stick with the approach in Area 1.

    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Martin
    Martin avatar
    51 posts
    Member since:
    Dec 2011

    Posted 25 May 2012 Link to this post

    Hi Anthony

    Thanks for the input, changing to outermarkup seems to work, so it was just a case of my staring my self blind on the issue :).

    Regarding area3:
    It seems to actually work as well once I changed to outermarkup, my guess is HtmlFindExpressions sees innerMarkup as a heirarchy
Back to Top