问题
I have FullCalendar
in my project:
https://www.primefaces.org/primereact/#/fullcalendar
I have 2 events at one day, I found first event by this code:
//tbody//td[count(//thead//td[@data-date='2019-08-06']/preceding-sibling::*)+1]
And I need to find second or more events.
<table>
<thead>
<tr>
<td data-date="2019-08-05"></td>
<td data-date="2019-08-06"></td>
<td data-date="2019-08-07"></td>
<td data-date="2019-08-08"></td> //find index of this element
<td data-date="2019-08-09"></td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2"></td>
<td rowspan="2" class="rrrr">event1 2019-08-06</td>
<td class="rrrr">event1 2019-08-07</td>
<td class="rrrr">event1 2019-08-08</td> //find this element by found index
<td rowspan="2"></td>
</tr>
<tr>
<td class="rrrr">event2 2019-08-07</td>
<td class="rrrr">event2 2019-08-08</td> //find this element by found index
</tr>
</tbody>
UPD How work //div[@class='fc-content-skeleton'][.//td[@data-date='2019-09-03']]//tbody/tr/td[count(//thead//td[@data-date='2019-09-03']/preceding-sibling::*)+1] at second day
回答1:
I would use the below xpath to get all the events and then iterate them. So, you don't have to worry even if the events' count change between the dates.
//div[@class='fc-content-skeleton'][.//td[@data-date='2017-02-12']]//tbody/tr/td[count(//thead//td[@data-date='2017-02-12']/preceding-sibling::*)+1]
Screenshot:
If you want to access any specific event then you can do it using the index as shown below. (wrapped entire xpath in ()
and then provide the index in []
).
(//div[@class='fc-content-skeleton'][.//td[@data-date='2017-02-12']]//tbody/tr/td[count(//thead//td[@data-date='2017-02-12']/preceding-sibling::*)+1])[2]
来源:https://stackoverflow.com/questions/57757779/get-second-event-from-fullcalendar-by-xpath