0

I am writing automation script for a Angular application. I am finding it very difficult is getting Xpath for the elements, i am stuck at getting the xpath for a toaster message that comes on the screen for a few seconds. Below is the code for it.

<span id="j_id0:j_id78" class="ng-scope">
<form class="ng-pristine ng-valid ng-submitted" style="">
<div class="slds-col slds-size--12-of-12 slds-p-top--small">
<notifications class="ng-isolate-scope" duration="5000" messages="getMessages('success')" type="toast">
<!-- ngRepeat: message in messages -->
<div class="ng-scope" ng-repeat="message in messages" style="">
<div class="slds-box slds-notify__content slds-grid ng-hide slds-theme--success" ng-show="type == 'message'" ng-class="{Error: 'slds-theme--error', Warning: 'slds-theme--warning', Success: 'slds-theme--success', Info: 'slds-theme--info'}[message.severity]">
<svg class="slds-icon slds-icon--small slds-m-right--small slds-col slds-no-flex" aria-hidden="true">
<div class="slds-col slds-align-middle">
<p class="ng-binding" ng-bind-html="message.description">Download operation successful</p>
</div>
</div>
<div class="slds-notify_container" ng-show="type == 'toast' || type == 'alert'">
<div class="slds-notify slds-notify--toast slds-theme--success" role="alert" ng-class="{Error: 'slds-theme--error', Warning: 'slds-theme--warning', Success: 'slds-theme--success', Info: 'slds-theme--info'}[message.severity]">
<button class="slds-button slds-button--icon-inverse slds-notify__close" name="close" title="Close" type="button" ng-click="closeAlert($index)">
<div class="slds-notify__content slds-grid">
<svg class="slds-icon slds-icon--small slds-m-right--small slds-col slds-no-flex" aria-hidden="true">
<p class="ng-binding ng-hide" ng-show="type == 'alert'" ng-bind-html="message.description">Download operation successful</p>
<div class="slds-col slds-align-right" ng-show="type == 'toast'">
<p class="ng-binding" ng-bind-html="message.description">Download operation successful</p>
</div>
</div>
</div>
</div>
</div>
<!-- end ngRepeat: message in messages -->
</notifications>
<notifications class="ng-isolate-scope" messages="getMessages('info')" type="toast">
<!-- ngRepeat: message in messages -->
</notifications>
<notifications class="ng-isolate-scope" messages="getMessages()" type="toast">
<!-- ngRepeat: message in messages -->
</notifications>
</div>

I tried this - //div/p[text() = 'Download operation successful'] but element is not located.

Could you please tell me what is the correct xpath? and also if you could guide me to some website where I can read more about automation for Angular application I will be grateful.

Thank you. Divya

yole
  • 92,896
  • 20
  • 260
  • 197
  • well the given xpath should work. please check whether it is present in any iframe tag. If yes, first you need to switch to the frame first and then find the element. Or is it about timing? – Naveen Kumar R B Nov 27 '16 at 10:50
  • refer Switching between frames here http://stackoverflow.com/a/40759300/2575259 – Naveen Kumar R B Nov 27 '16 at 10:54
  • Thank you for the reply Naveen, there is no iframe tag, i think this is a timing issue. The toaster message appears only for a few seconds and then disappears. Below is the parent class for the message:
    – Divya Reddy Nov 27 '16 at 14:28
  • I added a few more lines for better understanding. – Divya Reddy Nov 27 '16 at 14:30
  • Have you tried waiting for it? – JeffC Nov 28 '16 at 04:02
  • Yes I tried this: pCodesHomePage.waitTillSuccessToastLoads(driver); where waitTillSuccessToastLoads method calls the element. – Divya Reddy Nov 28 '16 at 04:08
  • try the answer here http://stackoverflow.com/questions/27941406/how-to-identify-element-for-notifications-that-disappear-within-few-seconds & http://stackoverflow.com/questions/12779575/selenium-how-to-locate-dynamic-element-like-notification-messages – Naveen Kumar R B Nov 28 '16 at 08:43

0 Answers0