首页 > 解决方案 > 使用 python 和 selenium 在日历中单击日期

问题描述

我很难弄清楚如何使用 Python 和 Selenium 在日历中单击开始和停止日期。下面是日历的 HTML 代码和它的外观截图。在日历中,您首先选择开始日期,然后选择结束日期,它会突出显示介于两者之间的所有内容。

在此处输入图像描述

<td class="day ng-binding ng-scope" ng-repeat="day in week" ng-class="{
        'now':isNow(day),
        'active':isSameDay(day),
        'disabled':(day.getMonth()!=date.getMonth() || isDayDisabled(day)),
        'after':isAfter(day),
        'before':isBefore(day)
      }" ng-click="setDate(day)" ng-bind="day.getDate()">6</td>

<th colspan="5" class="switch ng-binding" ng-click="setView('month')">2020 July</th>

<p class="cndrTitle ng-binding">Start Date</p>

<th colspan="5" class="switch ng-binding" ng-click="setView('month')">2020 July</th>

标签: pythonseleniumcalendar

解决方案


    public static void setcalender(String monthyear2, String date2,String monthyear3, String date3) {
        // driver.findElement(By.id("xpath of month  year")).click();

       

        while (true) {
            String CurrentMonth = driver.findElement(By.xpath("xpath of title]")).getText();
            if (CurrentMonth.equals(monthyear2)) {
                break;
            } else {

// click next arrow option until get user input 
                driver.findElement(By.xpath("xpath")).click();
            }
        }
       
        driver.findElement(By.linkText(date2)).click();
            }

    //click on thru date title
        driver.findElement(By.id("xpath")).click();
        

        while (true) {
            String CurrentMonth = driver.findElement(By.xpath("your xpath]")).getText();
            if (CurrentMonth.equals(monthyear3)) {
                break;
            } else {
// click next arrow until get date
                driver.findElement(By.xpath("xpath)).click();
            }
        }
        
        driver.findElement(By.linkText(date3)).click();
       
    
    }

推荐阅读