This is a migrated thread and some comments may be shown as answers.

IList<HtmlTable> allUsers = Find.AllByXPath returns no results, but it should

3 Answers 98 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jurij
Top achievements
Rank 2
Jurij asked on 22 Mar 2016, 10:18 AM

Hello,

I have a problem finding specific tag, which occurs only once. For example:

HTML code excerpt:

<table class="table" id="users-table">
<tbody>
<tr class="ng-scope" ng-click="user.id" ng-repeat="user in vm">
</tr>
</tbody>
</table>

 

Coded step used on HTML code above:

Manager.ActiveBrowser.RefreshDomTree();        
IList<HtmlControl> allUsers = Find.AllByXPath<HtmlControl>("table[@id='users-table']/tbody/tr");
int maxCount = allUsers.Count;
Log.WriteLine("Found: " + maxCount.ToString() + " elements.");

 

Problem that I'm facing:

If I run above coded step it returns maxCount = 0! Instead it should return 1, because one tr tag is available and can be found. If I use online XPATH validators they all return one result (one example of such validator http://codebeautify.org/Xpath-Tester). Let me know why this is happening and how can I solve this? If you have another idea how to solve my problem, please do let me know.

 

BR, Jurij

3 Answers, 1 is accepted

Sort by
0
Ivaylo
Telerik team
answered on 25 Mar 2016, 07:42 AM
Hello Jurij,

You are doing this quite complicated. There is no need to create a collection for the table rows, while you have the rows collection handy and only have to use it once you find the html table. I am providing you a sample code you could use instead yours:

HtmlTable table = Find.ById<HtmlTable>("users-table");
var rows = table.Rows;
Log.WriteLine(rows.Count.ToString());

Hope this works for you.

Regards,
Ivaylo
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Jurij
Top achievements
Rank 2
answered on 25 Mar 2016, 08:06 AM

Hello Ivaylo,

Perfect!!! this is exactly what I was looking for.

Thank you!!!

BR, Jurij

0
Ivaylo
Telerik team
answered on 25 Mar 2016, 12:06 PM
Hello Jurij,

You are most welcome.

Regards,
Ivaylo
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Jurij
Top achievements
Rank 2
Answers by
Ivaylo
Telerik team
Jurij
Top achievements
Rank 2
Share this question
or