【问题标题】:Clicking dates in a calendar with python and selenium [duplicate]使用python和selenium单击日历中的日期[重复]
【发布时间】:2020-07-17 00:15:56
【问题描述】:

我很难弄清楚如何使用 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>

【问题讨论】:

  • 你能添加正确的html吗?将您的代码和 html 作为图像粘贴不是一个好习惯,它很难调试和找到准确的解决方案。
  • 我对此感到抱歉

标签: python selenium calendar


【解决方案1】:
    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();
       
    
    }

【讨论】:

  • 你能分享你的日历网址,以便我可以浏览更多
  • youtube.com/watch?v=FtveSBQHvWE。点击这个链接它会帮助你
  • 我不能分享这个不是公共网站的 URL,我使用的是 Python 而不是 JAVA
  • 自动化时编程语言无所谓,试试我在python中的方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
相关资源
最近更新 更多