如何在不使用sendkey的情况下从日期选择器弹出窗口中选择当前date + 1 [英] How to select current date+1 from date picker popup, without using sendkeys

查看:107
本文介绍了如何在不使用sendkey的情况下从日期选择器弹出窗口中选择当前date + 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Selenium Web驱动程序Java,我想从日期弹出窗口中选择当前date + 1,我看到了其他与日期选择器相关的帖子,但它们仅与当前日期相关,或者使用sendkeys。我不想使用sendkeys。
以下是HTML代码

Using selenium web-driver Java, I want to select current date+1 from date popup, I have seen other post related to date picker but they are related to current date only or else using sendkeys. I don't want to use sendkeys. Below is the HTML code

    '<table id="dp_cal_calendar" class="calendar" classname="calendar" style="display: block; position: absolute; top: 282px; left: 574px;">
<tbody>
<tr>
<tr>
<td>
<table class="cells" classname="cells">
<thead class="caldayheading" classname="caldayheading">
<tbody>
<tr>
<tr>
<tr>
<tr>
<td class="wkend" classname="wkend">20</td>
<td class="wkend" classname="wkend">21</td>
<td class="wkday" classname="wkday">22</td>
<td class="wkday" classname="wkday">23</td>
<td class="wkday" classname="wkday">24</td>
<td class="wkday curdate" classname="wkday curdate">25</td>
<td class="wkday" classname="wkday">26</td>
</tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
<tr>
</tbody>
</table>'


推荐答案

假设您的日期选择器日历为表格格式
您可以使用:

Assuming ur date picker calendar is in table format you can use:

 public void checkDate(){

    String currentDate = null;
    int counter=0;

    WebElement tab = driver.findElement(By.id("tabid"));

    List<WebElement> rows= tab.findElements(By.tagName("tr"));

    for(int i =0;i<=rows.size()-1;i++){



        List<WebElement> columns=rows.get(i).findElements(By.tagName("td"));
        Iterator itr = columns.iterator();


        while(itr.hasNext()){

            WebElement we=(WebElement) itr.next();

            if(we.getText().equals(currentDate)){

                break;

            }

            counter=counter+1;
        }

    //element to be clicked is +1 to c

        driver.findElement(By.cssSelector("tr:nth-child(i) li:nth-child(counter+1)")).click();

    }

PS。这应该可以满足您的目的,但是当您当前的日期在表的最后一列时,您需要处理这种情况。

PS. This should serve your purpose but you need to handle the case when your current date is in last column of the table.

更新:

 String currDate= driver.findElement(By.cssSelector("table#dp_cal_calendar table.cells td.wkday.curdate")).getText();

 int dateToBeSelected = Integer.parseInt(currDate) + //no of days you want to add ;

 WebElement currentDate = driver.findElement(By.xpath("//table[@id='dp_cal_calendar']//table[@class='cells']//td[contains(text(),'"+String.valueOf(dateToBeSelected) +"')]")).click();

这篇关于如何在不使用sendkey的情况下从日期选择器弹出窗口中选择当前date + 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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