This is a migrated thread and some comments may be shown as answers.
Possible HtmlFindExpression bug
2 Answers 56 Views
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 21 May 2012, 07:37 AM
Hi

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 :)

Problem:
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:
Area1:
Finding elements with xpath which works as expected
Problem: none

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

Area3:
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.

Manager.LaunchNewBrowser(BrowserType.FireFox);
 
 
Thread.Sleep(10000); // Didn't bother with a real wait.
 
ActiveBrowser.RefreshDomTree();
 
 
// 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 Answers, 1 is accepted

Sort by
0
Accepted
Anthony
Telerik team
answered on 24 May 2012, 06:05 PM
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.

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Martin
Top achievements
Rank 1
answered on 25 May 2012, 09:47 AM
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
Asked by
Martin
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Martin
Top achievements
Rank 1
Share this question
or