0

enter image description here

i need to identify the relative xpath for the 2nd button highlighted in the image

Can someone help me

//*contains(@class,'fa fa-clock-o')

I used this. It identifies the first button again.

1
  • 1
    Do you have website link ?
    – PDHide
    May 8, 2021 at 19:58

2 Answers 2

1
<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):

//input[@id='end_time']/following-sibling::span/button

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.

0

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.

1
  • I can see the same company linked in almost every answer you posted. How is this relevant to this and other answers?
    – dzieciou
    Aug 15, 2021 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.