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

Unable to locate Page Element by Find.ByXPath

3 Answers 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jun
Top achievements
Rank 1
Jun asked on 22 Jul 2016, 08:28 PM

Hello,

I'm having trouble with using Find.ByXPath function in the Test Studio api.

 

<li class="k-item" role="treeitem" aria-selected="false " data-uid="bec31be9-e618-43fd-8060-a7df0c2c8e14">
<div class="k-mid">
<span class="k-icon k-plus" role="presentation"></span>
<span class="k-checkbox-wrapper" role="presentation">
<input tabindex="-1" class="k-checkbox" id="_bec31be9-e618-43fd-8060-a7df0c2c8e14" type="checkbox"/>
<label class="k-checkbox-label" for="_bec31be9-e618-43fd-8060-a7df0c2c8e14"></label></span>
<span class="k-in">Checkbox Node Text</span>
</div></li>

The problem with locating HtmlControl started with having the dynamic IDs that are generated by Kendo. They change all the time, so we need to find a way to locate the controls without using IDs. I talked with Dev team, and it concluded it is not feasible to change these IDs or add unique name tags.

In this case, I want to check the checkbox of "Checkbox Node Text". I thought xpath maybe a good way to do it by relatively searching from the Span Tag of "Checkbox Node Text".

The Find.ByXpath function works partially but not when I try to traverse relatively. Maybe my xpath syntax is off, but here is what I tried


First:
Element hc = Pages.MYPage0.FrameReal.Find.ByXPath("//span[text()='Checkbox Node Text']");
This works. It finds the correct element and I can operate on it.

Second:
Element hc = Pages.MYPage0.FrameReal.Find.ByXPath("//span[text()='Checkbox Node Text']/preceding-sibling::span[@class='k-checkbox-wrapper']/child::input");

This doesn't work. Null object.

Third:
Ultimately, this is what I want to get:
Element hc = Pages.MYPage0.FrameReal.Find.ByXPath("//span[text()='Checkbox Node Text']/preceding-sibling::span[@class='k-checkbox-wrapper']/child:input");

This doesn't work. Null object.

I have tried many combinations. For some reason, the relative traverse in xpath such as parent, child, preceding-sibling, etc not being processed.

I appreciate your advice! Thank you!

 

 

3 Answers, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 27 Jul 2016, 02:22 PM
Hi Jun,

Telerik Test Studio does not support relative XPaths and therefore only your first listed try was successful and you were able to find and interact with the element.

Please also be informed that using find expressions based on XPaths is strongly discouraged since this would make your tests highly unreliable. The reason for that is that each tiny change in the tested application could affect the used XPaths and result into failing test due to not found elements. 

Here you could find further details on how Test Studio generates its find logic and how it could be changed. I hope this information would be helpful to you! 

Regards,
Elena Tsvetkova
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Jun
Top achievements
Rank 1
answered on 27 Jul 2016, 04:34 PM

Hi Elena,

Thank you for your reply! I have another somewhat related question.

I'm dealing with Kendo dynamically generated IDs. Most of our html tags does not have a unique id. Such as what you see in the above: <input tabindex="-1" class="k-checkbox" id="_bec31be9-e618-43fd-8060-a7df0c2c8e14" type="checkbox"/>. It changes every time when relaunch the web app.

We are using Kendo UI for the widgets which I believe has to do with dynamically generated IDs. Is there any support in the Telerik Test Studio to handle these dynamically generated ID. The problem I'm having is to accurately identify HTML controls. That's why I was looking into the Find.ByXpath. I'm currently using DOM hierarchy to find HtmlControls. It's somewhat working but takes more time to do that. I'm just wondering if there is any type of support for dynamic IDs from the Test Studio.

Thank you!
Jun

 

0
Elena
Telerik team
answered on 01 Aug 2016, 06:28 AM

Hi Jun,

Each testing framework will hit a difficulty handling dynamic IDs like these generated while creating Kendo controls. Test Studio framework cannot explicitly handle dynamic IDs as well. However there are still other static attributes or combination of parent and child elements' attributes that could be used. I am not sure if you are using the testing framework only or Test Studio itself but here is how you could use chained find expressions to locate your elements.

Please let me know if this would be more useful for your scenario. Otherwise please bear in mind that I will possibly need your application or sample code to test it on my side and assist you on that. Thank you!

Regards,

Elena Tsvetkova
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Jun
Top achievements
Rank 1
Answers by
Elena
Telerik team
Jun
Top achievements
Rank 1
Share this question
or