briley last edited by
Can anyone please help me how to use 'contains' in my xpath while selecting a date from datepicker. This is my xpath :
This xpath is giving me '16 elements matching'. It's giving me all the dates having digit 2. I wanted to select a specific date. I expected the xpath to give me one specific matching node.
Update copied from OP's answer attempt
Here is the first
of each row is different.
//**First <td> of first row----** <td class="dxeCalendarWeekNumber_Office2010Silver" id="UserDetails.EffectiveDate_DDD_C_AUX_0_0_8">36</td> //First <td> of second row ------- <td class="dxeCalendarWeekNumber_Office2010Silver" id="UserDetails.EffectiveDate_DDD_C_AUX_0_0_9">37</td>
id is different which will make the date '2' as unique I tried with---
//*[@id="UserDetails.EffectiveDate_DDD_C_mt"]/tbody/tr/td[contains(text(), '2')] //td[@id='UserDetails.EffectiveDate_DDD_C_AUX_0_0_8']
As a result showing "0 element matching".
Your xpath is doing exactly what it is supposed to do: return every
element descended from an element with
If you wish to select only the 2nd of the current month you can use one of these methods:
td[text() = '2']- this will work if there is no white space in the element text and the element for the 2nd is not listed as '02'. If your calendar widget shows the first few days of the next month or is a floating calendar showing a certain number of days before and/or after the current date you will get more than one result.
- If your calendar widget has more than one
text() = '2'you'll need to use another method. Exactly what you use will depend on how the widget is configured.
- If the widget uses a different style or class for the current month, you can add a filter on that.
- If there's an attribute on the
that identifies the month you can add a filter on that.
- If there's any kind of
onclickattribute that's unique to the date you want, you can filter on that.
Without seeing the HTML of the widget there really isn't much more help anyone can give you.