使用Selenium webdriver从日期选择器中选择日期

Gok*_*kul 3 testing automated-tests selenium-webdriver

我有一个带有文本框字段的网页.靠近它的日历图标.当我点击日历图标时,会显示日历视图.我认为它不是一个jquery日历.任何人都可以提供一个示例来自动化这种类型的日期选择器.

Pan*_*yar 7

我试过这段代码,它也适用于你:

            DateFormat dateFormat2 = new SimpleDateFormat("dd"); 
            Date date2 = new Date();

            String today = dateFormat2.format(date2); 

            //find the calendar
            WebElement dateWidget = driver.findElement(By.id("dp-calendar"));  
            List<WebElement> columns=dateWidget.findElements(By.tagName("td"));  

            //comparing the text of cell with today's date and clicking it.
            for (WebElement cell : columns)
            {
               if (cell.getText().equals(today))
               {
                  cell.click();
                  break;
               }
            }
Run Code Online (Sandbox Code Playgroud)


小智 6

你可以在Selenium中以多种方式处理.

您可以使用直接单击操作来选择值

要么

您可以编写通用xpath来匹配日历中的所有值,并根据需要单击特定日期.

我已经写了详细的帖子.

希望它会有所帮助

http://learn-automation.com/handle-calender-in-selenium-webdriver/