Reputation: 4425
I'm trying to click on an element and after that want to select date between today and last day.
I'm able to click on Position Added Date element but I'm stuck down here "How can I select First date picker and select last day, and then click on To and select today date.
here is xpath
//*[contains(text(), 'Position Added Date:')]/input[@class='datetime-picker-date']
Here is element code that is being displayed after clicking the dropdown
<div class="jquery-ui-v1-10-3 dropdown-filter-edit-popup group" data-bind="control: EditorPopup" style="display: block;">
<a class="clear-filters" href="#" data-bind="click: Clear, css: { disabled: !CanClear() }">Clear Items</a>
<button data-bind="visible: HelpButtonVisible, click: HelpClick, css: {close: HelpOpen() == true }" class="help close" style="display: none;"></button>
<div class="filter-content" data-bind="control: EditViewModel, event: { keydown: EditorKey }"><div class="date-range-filter Edit">
<div class="form-group">
<label class="">From:</label>
<div data-bind="control: From" class=""><!-- ko if: !HideDate -->
<input type="text" class="datetime-picker-date hasDatepicker input-sm" data-bind="value: Date, valueUpdate: 'keyup', jqWidget: { datepicker: DatePickerArgs }, assignTo: DateField, attr: { 'readonly': IsReadOnly() }, enable: IsEnabled, css: { 'input-sm': SmallSize }" id="dp1474822442990">
<!-- /ko -->
<!-- ko if: !HideTime --><!-- /ko --></div>
</div>
<div class="form-group">
<label class="">To:</label>
<div data-bind="control: To" class=""><!-- ko if: !HideDate -->
<input type="text" class="datetime-picker-date hasDatepicker input-sm" data-bind="value: Date, valueUpdate: 'keyup', jqWidget: { datepicker: DatePickerArgs }, assignTo: DateField, attr: { 'readonly': IsReadOnly() }, enable: IsEnabled, css: { 'input-sm': SmallSize }" id="dp1474822442991">
<!-- /ko -->
<!-- ko if: !HideTime --><!-- /ko --></div>
</div>
</div>
</div>
</div>
I cannot go with ids, as these are dynamics.
Please advise.
Thanks
Upvotes: 0
Views: 248
Reputation: 23805
Instead of opening calendar and select date, you can use .sendKeys()
to enter date in appropriate format as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
Enter From
date :-
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[data-bind*='From'] > input.datetime-picker-date"))).sendKeys("From data in expected date format");
Enter To
date :-
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[data-bind*='To'] > input.datetime-picker-date"))).sendKeys("To date in expected date format");
Upvotes: 1