使用 Selenium webdriver 从日期选择器中选择一个日期 [英] Select a date from date picker using Selenium webdriver

查看:27
本文介绍了使用 Selenium webdriver 从日期选择器中选择一个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本框字段的网页.旁边有一个日历图标.当我单击日历图标时,会显示一个日历视图.我认为它不是 jquery 日历.谁能提供一个示例来自动化这种类型的日期选择器.

I have a webpage with a textbox field. A calender icon near it. When i click on the calender icon a calender view is displayed. I think its not a jquery calender. Can anyone provide an example to automate this type of date pickers.

推荐答案

我试过这个代码,它也可能对你有用:

I tried this code, it may work for you also:

            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;
               }
            }

这篇关于使用 Selenium webdriver 从日期选择器中选择一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆