1

I have a problem that I just can't find the answer to. I'm usually good in selecting specific elements in this spaghetti digit code. This time I'm stumped. Here is the code...

<div id="widget_dijit_form_DateTextBox_0_dropdown" class="dijitPopup dijitCalendarPopup" style="visibility: visible; top: 179.55px; z-index: 1000; left: 217.9px; right: auto; display: none;" role="presentation" dijitpopupparent="dijit_form_DateTextBox_0"> <table id="dijit_form_DateTextBox_0_popup" class="dijitCalendarContainer dijitCalendar" lang="" cellspacing="0" cellpadding="0" aria-labelledby="dijit_form_DateTextBox_0_popup_year" dojoattachevent="onkeypress: _onKeyPress" role="grid" style="-moz-user-select: none; top: 0px; overflow: hidden; width: 259px; visibility: visible;" dir="" widgetid="dijit_form_DateTextBox_0_popup"> <thead> <tbody class="dijitReset dijitCalendarBodyContainer" dojoattachevent="onclick: _onDayClick, onmouseover: _onDayMouseOver, onmouseout: _onDayMouseOut, onmousedown: _onDayMouseDown, onmouseup: _onDayMouseUp"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1463904000000"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1463990400000"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1464076800000"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1464163200000"> <td class="dijitCalendarSelectedDate dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1464249600000" tabindex="0"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1464336000000"> <span class="dijitCalendarDateLabel">27</span> </td> ... ... <div id="widget_dijit_form_DateTextBox_1_dropdown" class="dijitPopup dijitCalendarPopup" style="visibility: visible; top: 225px; z-index: 1000; left: 217.9px; right: auto;" role="presentation" dijitpopupparent="dijit_form_DateTextBox_1"> <table id="dijit_form_DateTextBox_1_popup" class="dijitCalendarContainer dijitCalendar dijitCalendarHover dijitHover dijitCalendarFocused dijitCalendarHoverFocused dijitHoverFocused dijitFocused" lang="" cellspacing="0" cellpadding="0" aria-labelledby="dijit_form_DateTextBox_1_popup_year" dojoattachevent="onkeypress: _onKeyPress" role="grid" style="-moz-user-select: none; top: 0px; overflow: hidden; width: 255px; visibility: visible;" dir="" widgetid="dijit_form_DateTextBox_1_popup"> <thead> <tbody class="dijitReset dijitCalendarBodyContainer" dojoattachevent="onclick: _onDayClick, onmouseover: _onDayMouseOver, onmouseout: _onDayMouseOut, onmousedown: _onDayMouseDown, onmouseup: _onDayMouseUp"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <tr class="dijitReset dijitCalendarWeekTemplate" role="row"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1432454400000"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1432540800000"> <td class="dijitCalendarCurrentDate dijitCalendarCurrentMonth dijitCalendarDateTemplate" role="gridcell" dijitdatevalue="1432627200000" tabindex="0"> <td class="dijitCalendarCurrentMonth dijitCalendarDateTemplate dijitCalendarHoveredDate" role="gridcell" dijitdatevalue="1432713600000"> <span class="dijitCalendarDateLabel">27</span> </td> 

I am trying to select the second "27". If I use this xpath statement

//*[contains(@class, 'dijitCalendarCurrentMonth')][contains(., '27')] 

It returns both elements. So, I need to only select the one that is under

id="dijit_form_DateTextBox_1_popup" 

I've tried the following... All return no matching nodes...

//*[@id='dijit_form_DateTextBox_1_popup' and contains(@class, 'dijitCalendarCurrentMonth') and contains(., '27')] //*[@id='dijit_form_DateTextBox_1_popup'][contains(@class, 'dijitCalendarCurrentMonth')][contains(., '27')] //*[@id='dijit_form_DateTextBox_1_popup'][contains(@class, 'dijitCalendarCurrentMonth') and contains(., '27')] 

What am I doing wrong?

1 Answer 1

3

With [@id='dijit_form_DateTextBox_1_popup'] you are looking for the text 27 in table tag itself which does not contain the text 27. If you remove that it should find the td that contains the span containing text 27. And, since the td does not have any id attribute with [@id='dijit_form_DateTextBox_1_popup'] it does not find any match either. Try

//table[@id='dijit_form_DateTextBox_1_popup']//span[contains(.,'27')] 

I am also seeing the the span containing the text 27 is the only span in that table. For better performance, I think you should try the following css instead.

#dijit_form_DateTextBox_1_popup span 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.