i need to identify the relative xpath for the 2nd button highlighted in the image
Can someone help me
I used this. It identifies the first button again.
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.Sign up to join this community
<div class="input group"> <input id="end_time"></input> <span class="input-group-btn"> <button class="btn btn-default"> <i class="fa fa-clock"></i> </button> <span> </div>
You would want to use the following selector for the button (not the icon in the button, because the button has the click/event handler):
Which reads something like: "//" starting anywhere on the page, find an "input" whose "id" is "end_time", then get the "following-sibling" element that is a "span", and then finally the "button" under that.
Most of the professional software testing companies keep scope of their automation frameworks enough high to handle different types of such scenarios through wide variety of reusable locators and libraries. In this case, you can use 'Parent-Child relationship' concept in which, although your child xpaths(as mentioned) are same but as shown in DOM structure, parent xpaths are different. Hence, you can create a combination of unique parent + child locator to create a resultant required unique xpath.
Below mentioned is required xpath for clock symbol corresponding to end time which will be unique on entire page- //input[@id='end_time']/../span/button/i[@class='fa fa-clock-o']
Note:- If you have multiple such buttons, you can make this locator dynamic instead of creating redundant xpaths.