简体   繁体   English

如何使用硒webdriver在Datepicker中选择开始日期和结束日期?

[英]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. 我在Eclipse中使用Selenium webdriver。

Firebug shows me a start date with xpath but when i execute with java, the xpath is never found. Firebug向我展示了xpath的开始日期,但是当我使用java执行时,却找不到xpath。 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. 例如开始日期应为:20/08/2014,结束日期= 31-08-2014您能帮我吗,谢谢。

Here is the html code for the date picker: 这是日期选择器的html代码:

<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: 找不到此示例,我使用java执行:

driver.findElement(By.xpath("html/div/..")).click(); 。driver.findElement(By.xpath( “HTML / DIV / ..”))点击();

I would recommend you to use alternative CSS selector approach. 我建议您使用其他CSS选择器方法。 To resolve your issue try the following: 要解决您的问题,请尝试以下操作:

1)[START DATE PICK ATTEMPT] try to click on the div element 1)[START DATE PICK ATTEMPT]尝试点击div元素

<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: 2)[START DATE PICK ATTEMPT]尝试以孩子的身份单击上面div以下的输入:

 <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 3)点击[END DATE PICK ATTEMPT]点击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 4)[END DATE PICK ATTEMPT]点击输入

 <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. 尝试这些替代方法,并告诉它们是否对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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