简体   繁体   English

无法在日期选择器中选择日期

[英]Unable to select date in datepicker

I'm testing a widget where I have to enter a start and end date using a calender. 我正在测试一个小部件,其中必须使用压延机输入开始日期和结束日期。 In real life use I select the option to enter dates from a drop down, a calender then appears where I have to click a start and an end date. 在现实生活中,我选择从下拉菜单中输入日期的选项,然后出现日历,这时我必须单击开始日期和结束日期。 Only after I click on 2 days the date fields are filled. 只有在我单击两天后,日期字段才被填写。 I have no problems doing this manualy but automating the test is proofing difficult. 我手动进行此操作没有问题,但是自动化测试非常困难。 Here's a few screenshots to illustrate what I'm trying to do. 这是一些屏幕截图,以说明我正在尝试执行的操作。 After selecting the option to enter dates the following screen appears: 选择输入日期的选项后,将出现以下屏幕:

在此处输入图片说明

Here I first click the From day (24), followed by the To day (31). 在这里,我首先单击“起始日”(24),然后单击“终止日”(31)。 Right after I click 31 the calender dissappears and the two date fields are filled with my selection: 当我单击31后,日历消失了,并且两个日期字段都充满了我的选择:

在此处输入图片说明

I'm trying to automate this with the following code: 我正在尝试使用以下代码将其自动化:

driver.findElement(By.xpath(".//span[@class='DateRangePicker__DateLabel'][contains(text(), '24')]")).click();
driver.findElement(By.xpath(".//span[@class='DateRangePicker__DateLabel'][contains(text(), '31')]")).click();

Here's part of the code I'm basing this on: 这是我基于的部分代码:

<span class="DateRangePicker__DateLabel" data-reactid=".0.1.1.0.1.1.1.0.0.2.0.1:$0-2016-4.1.1.$4.$1.2">24</span>

The code does not fail but the dates are not selected either. 代码不会失败,但是日期也不会被选择。

使用日期选择器中的硒- LINK

You could inspect id of from and to field. 您可以检查from和to字段的ID。 THen execute this command using javascript 然后使用javascript执行此命令

$('#id').datepicker("setDate", "date_you_want_in_right_format")

Note 1: You need to follow strictly date format that allowed by datePicker 注意1:您必须严格遵循datePicker允许的日期格式

Note 2: Tested with https://jqueryui.com/datepicker/ 注意2:已通过https://jqueryui.com/datepicker/测试

$('#datepicker').datepicker("setDate", "03/15/2016")

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

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