2010-06-02 60 views
0

我正在使用Selen測試日曆組件。在我的測試中,我想點擊當前日期。請幫助我完成XPath語句。我正在爲日曆組件添加HTML。需要用XPath語句進行Selenium測試的幫助

<input id="event_date" type="text" on="click then l:show.event.calendar" style="border: 1px solid rgb(187, 187, 187); width: 100px;" fieldset="new_event" decorator="redbox" validator="date"/> 
<img id="app_136" style="position: relative; top: 2px;" on="click then l:show.event.calendar" src="images/calendar.png"/> 
<div id="app_137" style="margin: 0pt; padding: 0pt;"> 
<div id="app_calendar_2" class="yui-calcontainer single withtitle" style="position: absolute; z-index: 1000;"> 
<div class="title">Select Event Date</div> 
<table id="app_calendar_2_cal" class="yui-calendar y2010" cellspacing="0"> 
<thead> 
<tr> 
</tr> 
<tr class="calweekdayrow"> 
<th class="calweekdaycell">Su</th> 
<th class="calweekdaycell">Mo</th> 
<th class="calweekdaycell">Tu</th> 
<th class="calweekdaycell">We</th> 
<th class="calweekdaycell">Th</th> 
<th class="calweekdaycell">Fr</th> 
<th class="calweekdaycell">Sa</th> 
</tr> 
</thead> 
<tbody class="m6 calbody"> 
<tr class="w22"> 
<td id="app_calendar_2_cal_cell0" class="calcell oom calcelltop calcellleft">30</td> 
<td id="app_calendar_2_cal_cell1" class="calcell oom calcelltop">31</td> 
<td id="app_calendar_2_cal_cell2" class="calcell wd2 d1 selectable calcelltop"> 
</td> 
<td id="app_calendar_2_cal_cell3" class="calcell wd3 d2 today selectable calcelltop selected"> 
<a class="selector" href="#">2</a> 
</td> 

我要點擊提前

<td id="app_calendar_2_cal_cell3" class="calcell wd3 d2 today selectable calcelltop selected"> 
<a class="selector" href="#">2</a> 
</td> 

由於描述的日期部分

mgeorge

回答

0

如何:

//td[contains(@class, 'today')]/a 

或者你可以使用一個CSS位置或

css=td.today > a 
+0

謝謝戴夫,都工作 – mgeorge 2010-06-02 09:53:09

+0

好聽,一般CSS定位器更好的速度和跨瀏覽器兼容性。 – 2010-06-02 10:26:52

+0

嗨,爲什麼CSS定位器比XPath定位器更好? – mgeorge 2010-06-02 13:27:27