如何在弹出窗口中从makemytrip中选择两个月的日期

u2nhd7ah  于 2021-09-13  发布在  Java
关注(0)|答案(2)|浏览(321)

我无法从makemytrip网站选择日期。
我第一次看到两个月。
我选择html代码、我的selenium代码和屏幕截图作为参考。

<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--outside"></div><div class="DayPicker-Day" tabindex="0" role="gridcell" aria-label="Wed Sep 01 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>1</p><p class=" todayPrice">3234</p></div></div><div class="DayPicker-Day DayPicker-Day--selected" tabindex="-1" role="gridcell" aria-label="Thu Sep 02 2021" aria-disabled="false" aria-selected="true"><div class="dateInnerCell"><p>2</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Sep 03 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>3</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Sep 04 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>4</p><p class=" todayPrice">2966</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Sep 05 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>5</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Sep 06 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>6</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Sep 07 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>7</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Sep 08 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>8</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Sep 09 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>9</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Sep 10 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>10</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Sep 11 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>11</p><p class=" todayPrice">2966</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Sep 12 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>12</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Sep 13 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>13</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Sep 14 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>14</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Sep 15 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>15</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Sep 16 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>16</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Sep 17 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>17</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Sep 18 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>18</p><p class=" todayPrice">2966</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Sep 19 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>19</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Sep 20 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>20</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Sep 21 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>21</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Sep 22 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>22</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Sep 23 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>23</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Fri Sep 24 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>24</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sat Sep 25 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>25</p><p class=" todayPrice">2966</p></div></div></div><div class="DayPicker-Week" role="row"><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Sun Sep 26 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>26</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Mon Sep 27 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>27</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Tue Sep 28 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>28</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Wed Sep 29 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>29</p><p class=" todayPrice">2966</p></div></div><div class="DayPicker-Day" tabindex="-1" role="gridcell" aria-label="Thu Sep 30 2021" aria-disabled="false" aria-selected="false"><div class="dateInnerCell"><p>30</p><p class=" todayPrice">2966</p></div></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></div></div>
List<WebElement> dates=driver.findElements(By.xpath("//div[@aria-disabled='false']//div"));
    String first_month_year=driver.findElement(By.xpath("(//div[@class='DayPicker-Caption']//div)[1]")).getText();
    System.out.println(first_month_year);
    String second_month_year=driver.findElement(By.xpath("(//div[@class='DayPicker-Caption']//div)[2]")).getText();
    System.out.println(second_month_year);
    String first_month=first_month_year.split("")[0].trim();
    String second_month=second_month_year.split("")[0].trim();
    String first_year=first_month_year.split("")[1].trim();
    String second_year=second_month_year.split("")[1].trim();
    while(!(first_month.equals("September")&& first_year.equals("2021")) || (second_month.equals("September") && second_year.equals("2021")))
    {
        driver.findElement(By.xpath("//span[@class='DayPicker-NavButton DayPicker-NavButton--next']")).click();

    }

xmakbtuz

xmakbtuz1#

为什么不根据要选择的日期创建一个动态日期选择器呢。我希望这就是你所指的和看到的。
xpath:

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

代码:

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

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+"]"));
    }

iszxjhcz

iszxjhcz2#

这是定位器

'//p[normalize-space(text()) = "2"]'
List<WebElement> elements = driver.findElements(By.xpath("//p[normalize-space(text()) = '2']"));
elements.get(0).click(); //For 2nd August
elements.get(1).click(); //For 2nd September

您可以根据需要更改日期。

相关问题