简体   繁体   中英

How to select a Start and End date in a Datepicker using selenium webdriver?

i have to generate a report with a datepicker. I use Selenium webdriver with Eclipse.

Firebug shows me a start date with xpath but when i execute with java, the xpath is never found. So i read some informations about the date picker but i'm not able to find the start date and end date.

for example the start date should be : 20/08/2014 and end date=31-08-2014 Can you help me, thank you.

Here is the html code for the date picker:

<div class="input-append date datepicker-start" data-date-format="yyyy-mm-dd">
            <input class="span2 start-date" type="text" value="2014-08-20" placeholder="YYYY-MM-DD" size="16" name="start"></input>
            <span class="add-on">
                <i class="enticon-calendar"></i>
            </span>
        </div>
    </div>

</div>
<div class="control-group">

    <label class="control-label">

        End Date

    </label>
    <div class="controls">
        <div class="input-append date datepicker-end" data-date-format="yyyy-mm-dd" data-date="">
            <input class="span2 end-date" type="text" value="2014-08-31" placeholder="YYYY-MM-DD" size="16" name="end"></input>
            <span class="add-on">
                <i class="enticon-calendar"></i>
            </span>
        </div>
    </div>

</div>

this example is not found i execute with java:

driver.findElement(By.xpath("html/div/..")).click();

I would recommend you to use alternative CSS selector approach. To resolve your issue try the following:

1)[START DATE PICK ATTEMPT] try to click on the div element

<div class="input-append date datepicker-start" data-date-format="yyyy-mm-dd">

=> click operation:

driver.findElement(By.cssSelector("div.input-append.date.datepicker-start")).click();

2) [START DATE PICK ATTEMPT] try to click on the input following div above as a child:

 <input class="span2 start-date" type="text" value="2014-08-20" placeholder="YYYY-MM-DD" size="16" name="start"></input>

=> click operation:

driver.findElement(By.cssSelector("input.span2.start-date")).click();

3) [END DATE PICK ATTEMPT] clicking on the div

<div class="input-append date datepicker-end" data-date-format="yyyy-mm-dd" data-date="">

=> click operation:

 driver.findElement(By.cssSelector("div.input-append.date.datepicker-end")).click();

4) [END DATE PICK ATTEMPT] clicking on the input

 <input class="span2 end-date" type="text" value="2014-08-31" placeholder="YYYY-MM-DD" size="16" name="end"></input>

 driver.findElement(By.cssSelector("input.span2.end-date")).click();

try these ones alternative and tell whether they work you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM