Unable to select date in datepicker - java

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). Right after I click 31 the calender dissappears and the two date fields are filled with my selection:
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.

using datepicker in selenium - LINK

You could inspect id of from and to field. THen execute this command using javascript
$('#id').datepicker("setDate", "date_you_want_in_right_format")
Note 1: You need to follow strictly date format that allowed by datePicker
Note 2: Tested with https://jqueryui.com/datepicker/
$('#datepicker').datepicker("setDate", "03/15/2016")

Related

How to set an exact date and time in material ui date time picker component using selenium and java?

The website I'm working with has an identical datetimepicker component to MobileDateTimePicker shown in this page.
I can get past the date selection by using xpath of the exact day I want in calendar view however that doesn't work for the hours/minutes in the analog clock view shown after selecting a date.
Is there a specific way to select hours/minutes in material ui date time picker?
(Manually clicking on exact hours/minutes get the job done but selenium is throwing Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted error when when clicking on span class for the respective hour/minute(s) shown in analog clock.)
Any help is appreciated. Thanks in advance.

The value of jDateChooser is back to the default value

I'm using jDateChooser in NetBeans, when i run the program and choose any date, it is not choosing correctly.
For example, if i choose 05-05-2020, it shows 29-12-2018.
Also, if it catch the selected date, when i press on another item (any button or text field), the Date back to its default.
I didn't add any code related to it, only take it from tools box and put it on the Frame.
What is the problem?
The problem was that i am using wrong date format, it was YYYY-MM-dd, the correct one is yyyy- MM-dd

Customize Android CalendarView - Display DropdownMenu

I have a project where I use a CalendarView, the built in Calendar for android.
So, I'm facing some difficulties to achieve some specific tasks for this Calendar. And I really hope I can find the solution here on StackOverflow.
Is there any possible way of setting each day on a onClickListener?
If not, Then stop reading.
This is the problem I have:
I would like to display a dropdown menu from the selected day, with a few elements that the user can select. If the user select some element, than the state will change for the dropdown menu ONLY for the selected date i.e. if user click on 13/1 the dropdown should display 10 elements. If user select one value, "lunch", then the dropdown menu must change so if user click again only "lunch" and "delete" will appear, not the other 9 elements which were displayed from first user interaction.
The problem I have here, is that the dropdown menu is connected to ALL dates, so I believe I need a onClickListener for each date in the calendar, therefore I wonder if it is possible.
I have been struggling with using different libraries from the internet, especially from GitHub without any success so I hope there's a way of achieve this via the built-in calendar.
Best regards
Is there any possible way of setting each day on a onClickListener?
Yes.
Try this way, In your onClickListener,
1. You need calendar instance.
Calendar calInstance=Calendar.getInstance();
2. SimpleDateFormatter required.
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
3. Create a Date Object
Date date = new Date();
4. Create string to store current date on each click listener.
String currentDate=sdf.format(date);
5. Perform your required operations on this currentDate that you have received.

Java: event objects filtered by startDate just work for one-day events

i am looking for a function that helps me with the following problem:
There is a Java class called "Event". The "Event" class has the attributes "startDate" and "endDate". Some events are not just one day long they exist for example 2 weeks.
Than there is a dropdown menu where you can choose a date of the next following days. The events which have the same "startDate" of the one which is choosen will appear.
The Problem:
Events they exsist longer than just one day will only appear when you choose the "startDate". It should also appear when the event still take place on the choosen date.
For Example:
startDate is 2016-06-20
endDate is 2016-06-25
In the Dropdown you choose the date 2016-06-22, than the event will not appear.
Thank you a lot for any help.

sendKeys() not working in Date or Time edit boxes in Selenium Code

In Selenium Javascript, sendKeys() is not working in Date or Time edit boxes. When I use the below code, it didn't populate the values in the appropriate fields. Is there any alternate for sendKeys()?
String strDate = "10/10/2014" ;
driver.findElement(By.xpath(DateXpath)).sendKeys(strDate);
Even I tried by hard coding the value inside sendKeys(), like
driver.findElement(By.xpath(DateXpath)).sendKeys("10/10/2014");
but didn't work
sendKeys works when that field is clicked once, before entering value, Code as follows,
driver.findElement(By.xpath(DateXpath)).click();
driver.findElement(By.xpath(DateXpath)).sendKeys("10/10/2014");
Does the date box have a format displayed in it? Something like dd/MM/YYYY. If that is the case it is possible that while selenium is trying to enter values in the date field, the javscript for that date format is still running. so whatever values you enter via selenium gets very quickly over written by date format provided by javascript making it appear like your date value was never entered. You can try putting a simple delay before entering the date value.

Categories

Resources