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

XPath and HTMLPath properties of an element

2 Answers 300 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 24 Nov 2016, 03:00 AM

I am trying to define xpath as one of the find settings for an element in the element repository. I am replacing the automatically generated xpath with an xpath that works in the coded step using Find.ByXPath, but the identification fails after the auto generated xpath is replaced.

I would also like to know the difference between xpath and html path.

 

Default xpath generated: /article[1]/fieldset[1]/ol[1]/li[11]/span[2]/input[2]

Changed xpath: /ol/li[contains(span,'Speech conditions')]/span/input[@value='No'] (I have also tried adding the '@' escape character for the "," and "@" symbols in the xpath)

The following is the html of the page

<html class=" js flexbox canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg no-smil svgclippaths" lang="en"><head>
        <meta charset="utf-8">
        <title></title>
        <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon">
        <script src="https://ssl.google-analytics.com/ga.js" type="text/javascript" async=""></script><script src="/Scripts/App/namespace.js" type="text/javascript"></script>
        <script src="/Scripts/App/modernizr.custom.24465.js" type="text/javascript"></script>
        <link href="/Content/css?v=y9MbIqhxSJ9syvKPl6VvsW91UpoZTibWFIr7ztvYKyY1" rel="stylesheet" type="text/css">
        <link href="/Content/ClientStyles/2008/css?v=cEvFed-VjJeJdJgeSzGl8h4W3IKEazh8p7RiAX-0XZk1" rel="stylesheet" type="text/css">
        
        <link href="/Content/themes/base/css?v=AumV9aQh6a_U8B-s6SUUgfjxQegD-CiF3g84ONgQrY01" rel="stylesheet" type="text/css">

        <meta name="viewport" content="width=device-width">
        
        <script type="text/javascript">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', '']);
            _gaq.push(['_trackPageview']);

            (function () {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();

        </script>

    </head>
    <body>
    
    <noscript> &lt;p class="alert-message alert-message-long alert-message-long-all"&gt;Your browser does not support JavaScript!&lt;/p&gt;</noscript>


  


<div class="ajaxLoderLook" id="testAjaxImage" style="display: none;">
    <img alt="Loading..." src="/Images/ajaxloader.gif">

</div>

        <div class="content">
            <header>
                <div class="content-wrapper header-content">
                  
                    <img class="float-right main-logo" alt="logo" src="/Images/Logos/hannover_re.png">
                 
                        <a class="apply button decisionSummary" id="btnDecisionSummary" href="#">Decision Summary</a>
                            <div class="age">
                                <span>Age: 41</span>
                            </div>
                    
<fieldset>
    <h3>Applicant: Johnni Jones</h3>
    <h3>Age Next birthday: 41 (11/08/1976)</h3>
</fieldset>                
                </div>
            </header>
            <div id="body">
                <section class="content-wrapper main-content clear-fix">
                    
                    <div id="content">
                        
                        <div id="innerContent" style="visibility: visible;">
                            

 

<div class="statusbar-container">
    
<div class="statusbar">
        <div class="statusbar-item" style="display: block;">
            
            Review
        </div>
        <div class="statusbar-item" style="display: block;">
            
            Your declaration
        </div>
</div>
</div>

<article>
    <fieldset>
        <legend>Direct Medical</legend>
        <input name="categoryId" id="categoryId" type="hidden" value="3502">
        <input name="yesRequired" id="yesRequired" type="hidden" value="False">
        <ol data-bind="foreach: { data: questions, afterRender: initControls }">
            <!-- ko if: type == 'Group' --> 
            <li>
                <h4 data-bind="text: text">In the last 5 years have you suffered from, been diagnosed with or sought medical advice or treatment for:</h4>
            </li>
            <!-- /ko --> 
            <!-- ko if: type == 'YesNo' --><!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">High Blood Pressure (other than fully resolved pregnancy related high blood pressure)</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4548" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q1_1_BD">
                
                    <span data-bind="text: value">No</span><input name="4548" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q1_1_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">High Cholesterol</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4577" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q1_2_BD">
                
                    <span data-bind="text: value">No</span><input name="4577" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q1_2_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --> 
            <li>
                <h4 data-bind="text: text">Have you EVER suffered from, been diagnosed with or sought medical advice or treatment for:</h4>
            </li>
            <!-- /ko --> 
            <!-- ko if: type == 'YesNo' --><!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Lung or Breathing conditions (other than childhood Asthma), Digestive conditions or Urinary conditions</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4595" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_1_BD">
                
                    <span data-bind="text: value">No</span><input name="4595" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_1_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Gynaecological conditions, or Pregnancy</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="5448" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_8_BD">
                
                    <span data-bind="text: value">No</span><input name="5448" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_8_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Brain conditions, Nerve conditions, Recurrent Headaches, Migraines, Psychological or Emotional conditions</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4597" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_2_BD">
                
                    <span data-bind="text: value">No</span><input name="4597" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_2_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Cancer, Cysts, Growths, Polyps, Tumours or Thyroid conditions</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4599" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_3_BD">
                
                    <span data-bind="text: value">No</span><input name="4599" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_3_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Heart related conditions, Diabetes, Kidney, Gall Bladder, Pancreas or Liver conditions</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4601" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_4_BD">
                
                    <span data-bind="text: value">No</span><input name="4601" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_4_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Auto Immune Diseases or Blood conditions</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4603" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_5_BD">
                
                    <span data-bind="text: value">No</span><input name="4603" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_5_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Speech conditions, Eye conditions, Ear conditions or Non-Cancerous Skin conditions</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4605" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_6_BD">
                
                    <span data-bind="text: value">No</span><input name="4605" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_6_BD">
                </span>
            </li>          
            <!-- /ko --> 
        
            <!-- ko if: type == 'Group' --><!-- /ko --> 
            <!-- ko if: type == 'YesNo' --> 
            <li>
                <span class="question-text group-question-label" data-bind="text: text, css: { 'invalid-question': !answer.isValid() }">Back, Neck or Knee complaint or any disorder of the Joints, Bones or Muscles (e.g. Gout, Arthritis)</span>
                <span data-bind="foreach: $parent.answerOptions">
                    <span data-bind="text: value">Yes</span><input name="4607" type="radio" value="Yes" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_7_BD">
                
                    <span data-bind="text: value">No</span><input name="4607" type="radio" value="No" data-bind="value: key, attr: { name: $parent.qid, 'data-qcode': $parent.qcode }, checked: $parent.answer, css: { 'readonly': $parent.readOnly }" data-qcode="DMEDI00Q2_7_BD">
                </span>
            </li>          
            <!-- /ko --> 
        </ol>
    </fieldset>
</article>
<nav class="nav">
    <a title="navigate next" class="standout button float-right" href="#" data-bind="event:{ click: navigateNext }">Next</a>
    <a title="navigate previous" class="button float-left" href="#" data-bind="event:{ click: navigatePrevious }">Previous</a>

</nav>
<aside>
    <div class="aside-container">
        <p class="field-validation-error" data-bind="validationMessage: isDataValid"></p>
        <div class="help-text" data-bind="html: helpText.selectedText"></div>
        <div class="aside-footer help-text" data-bind="html: helpText.footerText">For more information please refer to the Product Disclosure Statement which contains all of the details of cover plus terms and conditions of cover.</div>
    </div>
</aside>
                    
                        </div>
                    
                    </div>
                </section>
            </div>
            <footer>
                <div class="content-wrapper">
                    <div class="float-left">
                        © Hannover Life Re of Australasia Ltd
                    </div>
                </div>
            </footer>
        </div>

         


        <script type="text/javascript">
            maz.baseUrl = '/';
        </script>
        <script src="/Scripts/Lib/js?v=QPWEIV3aAl4mBKiTff9diiX6D5tUEZmRw2CZauQq2M41" type="text/javascript"></script>
       

        <script src="/Scripts/App/Views/group.js" type="text/javascript"></script>
<script src="/Scripts/App/ajaxLoader.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function () {

                master.constructDecision();
                maz.utils.loadView(true);
            });
        </script>
        

    

<div tabindex="-1" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable" role="dialog" aria-labelledby="ui-dialog-title-dvDecisionSummary" style="outline: 0px; display: none; position: absolute; z-index: 30000;"><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" id="ui-dialog-title-dvDecisionSummary">&nbsp;</span><a class="ui-dialog-titlebar-close ui-corner-all" role="button" href="#"><span class="ui-icon ui-icon-closethick">close</span></a></div><div class="ui-dialog-content ui-widget-content" id="dvDecisionSummary"></div><div class="ui-resizable-handle ui-resizable-n"></div><div class="ui-resizable-handle ui-resizable-e"></div><div class="ui-resizable-handle ui-resizable-s"></div><div class="ui-resizable-handle ui-resizable-w"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se ui-icon-grip-diagonal-se" style="z-index: 1001;"></div><div class="ui-resizable-handle ui-resizable-sw" style="z-index: 1002;"></div><div class="ui-resizable-handle ui-resizable-ne" style="z-index: 1003;"></div><div class="ui-resizable-handle ui-resizable-nw" style="z-index: 1004;"></div></div></body></html>

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 28 Nov 2016, 01:12 PM
Hello Dirk,

As of your description I assume you are using the desktop Test Studio version and not the framework itself. Please note that Test Studio uses an intelligent element identification scheme to auto-generate find expressions based on unique attribute values and xpaths are used as a backup search only. Moreover xpaths are not quite reliable since they might need to be updated after each application update. 

Once an element is recorded you could access it in the Elements repository and change its find expression according the application specifics. As of the code you shared I would suggest you use the value of the element along with either its name or the custom attribute 'data-qcode'. These values are the same for the corresponding 'Yes' radio button though the value is different. Combining these two the element will be located successfully. 

Please note that Test Studio uses also chained find expressions and this particular case is quite a good example for that. 

Let me know if the above information would not be sufficient and further advice will be required. 

Regards,
Elena Tsvetkova
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Elena
Telerik team
answered on 28 Nov 2016, 01:33 PM
Hello Dirk,

Here is a screenshot I missed to attach. Thanks! 

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
Scott
Top achievements
Rank 1
Answers by
Elena
Telerik team
Share this question
or