0

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
    Searching by index may not work this time because your target date is #4 in `thead/tr`, but "event 2" is #2 in `tbody/tr[2]`. – Jack Fleeting Sep 02 '19 at 14:10
  • @JackFleeting Yep, but day with one event have class="" and rowspan, and day with same amount of events with my day have only class="", so probably need to count preceding-sibling days without rowspan – John Brewer Sep 02 '19 at 14:14
  • So just to be clear: is it always the case that in each `tbody/tr` there are only two `td`s with `class="rrrr"` (and which have no `rowspan`) and that your target event is always the 2nd of these two (like it is in `tbody/tr[2]`)? – Jack Fleeting Sep 02 '19 at 14:39
  • @JackFleeting No, if one day have 2 events and another day have 1 event, day with 1 event have class and rowspan, if day have not events - only rowspan, if some days have 2 events - only class, and target event place depends from how many preceding-sibling days have same or more amount of events – John Brewer Sep 02 '19 at 14:47
  • Then if i understand you correctly, the index location of `date-date` on `thead/tr` is really irrelevant. Are you simply just trying to select all events taking place on a specific `date-date`? – Jack Fleeting Sep 02 '19 at 15:09
  • @JackFleeting, no, for first from tbody no, but for next tr yes – John Brewer Sep 02 '19 at 15:14
  • But you xml in the questions says about the first `tr` in `tbody`: "event1 2019-08-08 //find this element by found index"? – Jack Fleeting Sep 02 '19 at 15:17
  • @JackFleeting, this work by your answer from previous question, and now I need to find second event – John Brewer Sep 02 '19 at 15:20

1 Answers1

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:

enter image description here

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]

enter image description here

supputuri
  • 13,644
  • 2
  • 21
  • 39