I need to know how to set Date into combo box Calendar Date Picker field from Source Input text file.
Iam using application build on .jnlp file (swing based application components) and using RobotFramework along with RemoteSwing Library.
Scenario Details :- We have source file which has Date which on basis of meeting IF condition will then set this Date field dropdown/combo box with this source date.
Since, this dropdown/combobox is a Calendar Date Picker field rather than just a textbox it is becoming difficult to set the source date value in it. Any suggestions ?
Some of the date pickers, you can ignore the calendar picker and just overwrite the date, if that works it’s usually the easiest way.
Otherwise , you’ll need to break up the date into parts, and use those parts to manipulate the calendar picker (in a web page these will show up inside a dynamic element often a div)
If you don’t want add a seperate library for breaking up the dates it’s easy to do with the python split and the builtin Evalutate keyword like this:
Can you please elaborate with an example in this doubt context? sorry I was not able to understand.
even if its able to split date by’-’ or ‘/’ but how it will set the date combo box field?
Iam not able to update the Image here otherwise it would be helpful to visualize what combobox Iam talking about.
As explained, this app is a .jnlp app not browser so finding out the components/elements their xpath, css etc are not available. We are using remoteswinglibrary with roboframework.
So, this is a dropdown (remoteswinglibrary directs to use combobox for dropdown). When you click to extend this it shows calendar picker to select the required date. I have a date in the source file which is stored in some Variable name. So, If somehow if my code is able to take the variable name then it would work. But, for some reason, its not taking it. Below is what I tried unsuccessfully :-
Select From Combo Box 0 ${datevaluefrmsourcefile}
Type Into Combobox 0 ${datevaluefrmsourcefile}
I Haven’t tested a .jnlp app before, so on that side i’ll have to let someone else answer what the keywords you need are, I’m guessing your using one of the java libraries (swing?), so below i’ll put <JavaLibrary>, replace this with whichever library you are using
I’ve given you an example below with a web datepicker, I know it’s not going to be the same, but the concepts should be.
What I expect you’ll need to do:
Replace the Load JQuery Theme Page keyword in my example with the navigation to your datepicker (you should already have this)
Replace the selenium keyword Get Text with the <JavaLibrary> equivalent keyword
Replace the selenium keyword Click Link with the <JavaLibrary> equivalent keyword
After that you should be able to just re-use my keywords and have a working example
Dave.
*** Settings ***
Library SeleniumLibrary
Library Collections
*** Test Cases ***
JQuery Datepicker Date In Past
Load JQuery Theme Page
Select Date From DatePicker 2020-01-01
Close Browser
JQuery Datepicker Date In Future
Load JQuery Theme Page
Select Date From DatePicker 2024-02-29
Close Browser
*** Keywords ***
Load JQuery Theme Page
Open Browser https://jqueryui.com/themeroller/ Chrome
Scroll Element Into View id:datepicker
Scroll Element Into View id:progressbar
# Capture Page Screenshot
Select Date From DatePicker
[Arguments] ${NewDate}
${NewYear} ${NewMonth} ${NewDay}= Evaluate "${NewDate}".split("-")
${NewMonth}= Convert To Integer ${NewMonth}
${NewDay}= Convert To Integer ${NewDay}
Wait Until Keyword Succeeds 1 min 100ms Move DatePicker To Year ${NewYear}
Wait Until Keyword Succeeds 1 min 100ms Move DatePicker To Month ${NewMonth}
Click Link //div[@id="datepicker"]//a[@data-date="${NewDay}"]
Capture Page Screenshot
Move DatePicker To Year
[Arguments] ${NewYear}
# Capture Page Screenshot
${CurrYear}= DatePicker Current Year
Run Keyword If ${NewYear}>${CurrYear} DatePicker Click Next Month
Run Keyword If ${NewYear}<${CurrYear} DatePicker Click Prev Month
${CurrYear}= DatePicker Current Year
Should Be Equal As Numbers ${CurrYear} ${NewYear}
# Capture Page Screenshot
Move DatePicker To Month
[Arguments] ${NewMonth}
# Capture Page Screenshot
${CurrMonth}= DatePicker Current Month
Run Keyword If ${NewMonth}>${CurrMonth} DatePicker Click Next Month
Run Keyword If ${NewMonth}<${CurrMonth} DatePicker Click Prev Month
${CurrMonth}= DatePicker Current Month
Should Be Equal As Numbers ${CurrMonth} ${NewMonth}
# Capture Page Screenshot
DatePicker Current Year
# //div[@id="datepicker"]//span[@class="ui-datepicker-year"] # Year
${DPYear}= Get Text //div[@id="datepicker"]//span[@class="ui-datepicker-year"]
[Return] ${DPYear}
DatePicker Current Month
# //div[@id="datepicker"]//span[@class="ui-datepicker-month"] # Month
@{Months}= Create List 0thMonth January February March April May June July August September October November December
${DPMonth}= Get Text //div[@id="datepicker"]//span[@class="ui-datepicker-month"]
${DPNumMonth}= Get Index From List ${Months} ${DPMonth}
[Return] ${DPNumMonth}
DatePicker Click Prev Month
Click Link //div[@id="datepicker"]//a[@title="Prev"] # Prev Month
DatePicker Click Next Month
Click Link //div[@id="datepicker"]//a[@title="Next"] # Next Month
It didnt work for me.
Actually, as said, we are using remoteswinglibrary and Application is JLNP file (kind of windows based).
So, we do not have a way to get the Element attribute details.
Thats why Iam kind of stuck here. I also thought of using JSExecutor but again I need Element, Driver details to get this work.
You code works for me when I select current year, but when I choose previous or later years, my code doesnt works, to pick years I need to click on the current month(Which is in title) and the select months, after which date selection screen will come up: Here is how the calender looks like:
In the above screenshot, I need to click on current month which is August(highlighted in red) and then year and month selection will come, after we select the month date screen will come up.
Ok I ran that example as is in the post above, it still works for me with that demo site. The only issue I got was:
[ WARN ] Error in file '/home/dave/Documents/tmp/Mohit/robouser.robot' on line 58: The '[Return]' setting is deprecated. Use the 'RETURN' statement instead.
[ WARN ] Error in file '/home/dave/Documents/tmp/Mohit/robouser.robot' on line 65: The '[Return]' setting is deprecated. Use the 'RETURN' statement instead.
This can be easily fixed by changing the last line in the keywords DatePicker Current Year and DatePicker Current Month from [Return] to RETURN .
This example was only ever intended as that, and example of how you might want to approach dealing with a date picker, if this was working on your application great, but if it’s not now you’ll need to look at what’s different in your application from the date picker in the demo site and make the necessary adjustments to match your application.
given you mention it’s not working for other years, check the xpath in the keyword DatePicker Current Year and check the value being returned by ${DPYear}, you probably need to just make an adjustment to that xpath and hopefully after that it’ll work again.