In the xpath above, you can see the value inside the first div-is getting changed everytime. ts not constant. I want to use a comman xpath format for the above case so that I can execute the test cases 20 times. How can this be done?

Following is the screenshot of how the page looks.

enter image description here

  • This is hard to answer without knowing the structure of the document.
    – user246
    Commented Apr 30, 2014 at 20:50
  • (dropmocks.com/mETuQJ). It is a calendar page, clicking on the horizontal lines, popup will openup allowing to book appointments. I want to locate the timeslots exactly. <div class="cal-event new-cal-event ui-corner-all ui-resizable ui-draggable" style="line-height: 18px; font-size: 10px; top: 80px; height: 40px; display: block;"> <div class="time ui-corner-all">01:00 am to 01:30 am</div> <div class="title">New Event</div> <div class="ui-resizable-handle ui-resizable-s"></div> </div> </div> </td> This is how the timeslots are created in the page
    – STE
    Commented May 2, 2014 at 16:35
  • Does the <div> that you want to access have any unique attribute? ID, class, value, etc?
    – Yash
    Commented May 6, 2014 at 11:17

3 Answers 3


This is not an answer, but I cannot comment yet, so please no downvotes. :-)

There were few views of this question, no answers, and unlikely any answer is coming. See:

So non-answer is: "don't do that" :-)

Can you change page/ask it to be changed?


driver.findElements(.//*[@id='colDiv_Apr282014']/div). It has to be findElements with 's' on end. That way You will get list of element. When filter obtained result if some not meet expected criteria.

  • @SkorpEN- Uniquely identifying the element somehow will be much easier. Using a list will complicate things, IMO, as he will have to uniquely identify the element in the list too.
    – Yash
    Commented May 6, 2014 at 11:24
  • But if elements id is changeing this is the simplest solution I know. Of course You could ask programmers for unique id or name, still if You can not change locators it is simple enough solution.
    – SkorpEN
    Commented May 6, 2014 at 11:28

Try with

.//*[@id='colDiv_Apr282014']//div[contains(concat(' ',normalize-space(@class),' '),' time ')]

Your Answer

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

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