How to handle DatePicker (Calendar Control) using selenium + Java? - java

I have a scenario to enter Date Of Birth for some agents. I gave Agent Names, DOB in excel.
I wrote the code in Java. But while running the script it is not working.
How can I automate Date Picker for the required date using Selenium?

Related

Cannot select a date range from jquery datepicker date range selector in Selenium JAVA

I'm struggling with selecting a date range from jquery datepicker date range selector using selenium web driver.
Following image shows the date picker.
I need to select a date range from this calendar. I've tried following links.
Link 1
Link 2
Only thing i found relevant is the following code segment.
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#class='demo-frame'][#src='/resources/demos/datepicker/default.html']")));
driver.findElement(By.id("datepicker")).click();
System.out.println("Datepicker Clicked");
But, it doesn't show how to select a date range from the date picker.
Thanks in advance. :-)
From my experience, it makes no sense to interact with such components via findElement calls. Unless you want to make your tests unstable. Such datepickers usually have public API, which could be accessed directly via JavascriptExecutor. Quick sample:
$( ".selector" ).datepicker( "setDate", "10/12/2012" );
could be used the following way:
executeScript("$( '.selector' ).datepicker( 'setDate', '10/12/2012' );");
So I'd recommend you to find out which JS library is used to render your datepicker, check their API, and access it directly the way I've written above.
Give a try to below code and lets see if it works.
I stole the code from select the Date Picker
((JavascriptExecutor)driver).executeScript ("document.getElementById('elementid').removeAttribute('readonly',0);"); // Enables the from date box
WebElement dateBox= driver.findElement(By.id("elementid"));
dateBox.clear();
dateBox.sendKeys("8-Dec-2014"); //Enter date in required format

Selenium web driver Date picker exists in page after the send keys?

I'm using send keys to input the value in date picker.. this is working absolutely fine, but most of the times date picker still displaying in the page after the send keys!! any idea how to remove date picker in page after the send keys???
Thanks in advance!!
If you click on the date picker, the date picker will be close automatically.
But you use send keys to input the value, you should send the key Enter after it.
Try to do it manually.

Date comparison in MongoDb and Java

I have to compare an EQUAL comparison between dates from UI and DB. Its working with below code
ExtJs Code :-
xtype: 'datefield'
,fieldLabel:'By Date'
,name: 'byDate'
,format: 'd-m-Y'
,flex:1
and Code in Java is :-
query.addCriteria(Criteria.where("bookingtime").regex(byDate, "i"));
The format d-m-Y gives me date in format 27-11-2016 or 15-10-2016. If the date in DB is as same as in date from UI ,like 27-11-2016 etc, this works like a charm.
But the problems arises when I select date in UI as 07-01-2016 which becomes 7-1-2016 in java. Since date in DB is in format 07-01-2016 and it fails the match and I get nothing.
Could you please help.

How to enforce format for String date in jsf 1?

i am sending hijri date to jsp page as String like:
1435/06/01
the format is YYYY/MM/DD
and in the ui:table when i make inspect element i can see the date as required 1435/06/01
but in the page is displayed as 1435/06/01 because the client windows date and time format is Arabic
but when the client changes the windows date and time format to english the date is displayed correctly.
is there's a way to enforce the display of my date and numbers to be exactly like the value i send from backend and ignore the client system date and time format ?

RichFaces 4.2 Calendar. How can I set the InputField of Calendar by JavaScript?

I have to copy a Date String at client side to the Calendar input field "renewal_date_input". The following JavaSript did not work:
document.getElementById('AddressDetails:renewal_date_input').value = renewalDateCombo.value.toString();
Although with:
alert("written date is: " + document.getElementById('AddressDetails:renewal_date_input').value);
We can read out the correct date string written previously.
But the string does not appear in the input field.
Manual Input is enabled:
enableManualInput="true"
Perhaps the JavaScript Function setInputField: function(dateStr, event) shipped with rich faces calendar.js could help, but how do I use it?
Use the setValue() function on the date component, passing a Date object as argument
var theCalendar = document.getElementById('AddressDetails:renewal_date_input');
theCalendar.setValue(document.getElementById('AddressDetails:renewal_date_input').getValue()); //Here I assume renewal_date_input is also a calendar component

Categories