Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

java - How to select date from makemytrip having two months in popup

I have problem selecting date from makemytrip website.
I am seeing two months for the first time.
I am selecting HTML code,my selenium code and screenshot for the reference.

<div class="DayPicker" lang="en"><div class="DayPicker-wrapper" tabindex="0"><div class="DayPicker-NavBar"><span tabindex="0" role="button" aria-label="Previous Month" class="DayPicker-NavButton DayPicker-NavButton--prev"></span><span tabindex="0" role="button" aria-label="Next Month" class="DayPicker-NavButton DayPicker-NavButton--next"></span></div><div class="DayPicker-Months"><div class="DayPicker-Month" role="grid"><div class="DayPicker-Caption" role="heading"><div>August 2021</div></div><div class="DayPicker-Weekdays" role="rowgroup"><div class="DayPicker-WeekdaysRow" role="row"><div class="DayPicker-Weekday" role="columnheader"><abbr title="Sunday">Su</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Monday">Mo</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Tuesday">Tu</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Wednesday">We</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Thursday">Th</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Friday">Fr</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Saturday">Sa</abbr></div></div></div><div class="DayPicker-Body" role="rowgroup"><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="0" role="gridcell" aria-label="Sun Aug 01 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>1</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Aug 02 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>2</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Aug 03 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>3</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Aug 04 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>4</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Aug 05 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>5</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Aug 06 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>6</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Aug 07 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>7</p><p class=" todayPrice">6858</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Aug 08 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>8</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Aug 09 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>9</p><p class=" todayPrice">16308</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Aug 10 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>10</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Aug 11 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>11</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Aug 12 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>12</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Aug 13 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>13</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Aug 14 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>14</p><p class=" todayPrice">6858</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Aug 15 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>15</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Aug 16 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>16</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Aug 17 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>17</p><p class=" todayPrice">6542</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Aug 18 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>18</p><p class=" todayPrice">5277</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Aug 19 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>19</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Aug 20 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>20</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Aug 21 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>21</p><p class=" todayPrice">6858</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Aug 22 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>22</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Aug 23 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>23</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Aug 24 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>24</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Aug 25 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>25</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Aug 26 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>26</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Aug 27 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>27</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Aug 28 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>28</p><p class=" todayPrice">6858</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Aug 29 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>29</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Aug 30 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>30</p><p class=" todayPrice">6858</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Aug 31 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>31</p><p class=" todayPrice">5268</p></div></div><div aria-disabled="true" class="DayPicker-Day DayPicker-Day--outside"></div><div aria-disabled="true" class="DayPicker-Day DayPicker-Day--selected DayPicker-Day--outside"></div><div aria-disabled="true" class="DayPicker-Day DayPicker-Day--outside"></div><div aria-disabled="true" class="DayPicker-Day DayPicker-Day--outside"></div></div></div></div><div class="DayPicker-Month" role="grid"><div class="DayPicker-Caption" role="heading"><div>September 2021</div></div><div class="DayPicker-Weekdays" role="rowgroup"><div class="DayPicker-WeekdaysRow" role="row"><div class="DayPicker-Weekday" role="columnheader"><abbr title="Sunday">Su</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Monday">Mo</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Tuesday">Tu</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Wednesday">We</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Thursday">Th</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Friday">Fr</abbr></div><div class="DayPicker-Weekday" role="columnheader"><abbr title="Saturday">Sa</abbr></div></div></div><div class="DayPicker-Body" role="rowgroup"><div class="DayPicker-Week" role="row"><div aria-disabled="true" class="DayPicker-Day DayPicker-Day--outside"></div><div aria-disabled="true" class="DayPicker-Day DayPicker-Day--outside"></div><div aria-disabled="true" class="DayPicker-Day DayPicker-Day-

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Why not create a dynamic date picker based on the date you want to select. I hope that's what you are referring to and looking at.

Xpath:

//*[@aria-label="Thu Sep 02 2021"]

Code:

 public By getSelectedLabel(String date){
        return By.xpath("//*[@aria-label="+date+"]");
    }

OR

 public static void main(String[] args) {
        clickOnSelectedLabel(driver, "Thu Sep 02 2021");
    }

    public void clickOnSelectedLabel(WebDriver driver, String date){
        driver.findElement(By.xpath("//*[@aria-label="+date+"]"));
    }

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...