I am trying to extract the Current Unix epoch time in milliseconds from this website but I failed. Here is my code
Document document = Jsoup.connect("https://www.freeformatter.com/epoch-timestamp-to-date-converter.html").get();
String content = document.getElementById("epochMs").text();
For some reason, the content is empty. Maybe I need to click on the href link first to stop the running timer? Any idea how to get the timestamp?
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
I am pretty new to CQ and I am adding a new field to an existing form.
I want to accept a date and time from the component dialog as strings. If I use xtype="datefield" and xtype="timefield" separately, I can get the date and time as strings just the way I need it. But, the UI looks bad and non-intiutive with two separate fields placed one below the other.
dialog.xml:
<startDate
jcr:primaryType="cq:Widget"
fieldLabel="Event Start Date"
fieldDescription="Select a date "
emptyText="Event start date "
name="./startDate"
format="d/m/Y"
xtype="datefield" />
<startTime
jcr:primaryType="cq:Widget"
fieldLabel="Event Start Time"
fieldDescription="Select a time "
emptyText="Event start time "
name="./startTime"
xtype="timefield" />
Java code in controller:
#Property(path = "startDate")
private String startDate;
#Property(path = "startTime")
private String startTime;
If I use xtype="datetime", the UI looks the way I like but the value is converted to UTC into a Date field.
dialog.xml
<startDateTime
jcr:primaryType="cq:Widget"
fieldLabel="Start Date & Time"
name="./startDateTime"
dateFormat="d/m/Y"
xtype="datetime"/>
Java code in controller:
#Property(path = "startDateTime")
private Date startDateTime;
This is of no use to me as I need the date and time as raw strings, the way they were entered. The need for obtaining date & time as strings is driven by the requirement which states 'The author should be able to enter a specific date and time that an event starts and ends at a particular city. So the author enters the date, time and timezone of the event'. I need to display the date&time on the page and also add a calendar link. The valueAsString option looked promising but does not give me date and time as strings. How can I achieve this?
Thanks in Advance
UPDATE:
Using the xtype="compositefield" suggested by #Sharath, I can achieve the desired UI but unfortunately the values are retained when I edit the component. The values are entered accurately and I can display it on the screen but when the component is edited, the fields go back to being empty. There were no changes in the java file.
Updated dialog.xml:
<items jcr:primaryType="cq:WidgetCollection">
<eStart jcr:primaryType="cq:Widget"
xtype="compositefield"
fieldLabel="Start"
fieldDescription="Select event start date & time">
<items jcr:primaryType="cq:WidgetCollection">
<startDate
jcr:primaryType="cq:Widget"
emptyText="Event start date "
name="./startDate"
format="d/m/Y"
xtype="datefield"
width="240"/>
<startTime
jcr:primaryType="cq:Widget"
emptyText="Event start time "
name="./startTime"
xtype="timefield"
width="180"/>
</items>
</eStart>
*
*
</items>
There are two ways to do this :
1) Use a compositefield and place the date and time fields within it. Compositefield displays the widgets within it in a horizontal row. With this method the fields will be displayed like the datetime xtype but still store values independently as strings.
2) Use datetime xtype and read the value as String instead of Date and split the value by "T". (I'd go with 1)
I think i was wrong about the composite field, it displays and stores the value but does not read back the values next time (inspite of the get request to the node returning those values )
Here's an alternative
{
xtype:"panel",
border:false,
layout:"hbox",
jcr: primaryType:"cq:Widget",
items:{
jcr: primaryType:"cq:WidgetCollection",
label:{
flex:"30",
xtype:"label",
jcr: primaryType:"cq:Widget",
text:"Date Time"
},
datefield:{
flex:"40",
xtype:"datefield",
name:"./date",
jcr: primaryType:"cq:Widget"
},
timefield:{
flex:"30",
xtype:"timefield",
name:"./time",
jcr: primaryType:"cq:Widget"
}
}
}
I think datetime is the easier option. With the Date object you can then use http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html to get the date in the required format.
You can use the same formatting in the dialog as well as the output.
Another advantage is that you could filter and sort nodes of this type by Date, as opposed to save the values as Strings.
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?
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 ?