• Dynatrace Recorder





1. Record your base script, entering in any valid date into the date selection fields. 
IMPORTANT: Be sure to perform an action on each date selection field, even if the application auto-populates a date for you. This will allow you to have a reference to the field's locator when adding in the dynamic dates. 

2. Before the date selection action insert a custom action. 
3. Set the Target Window to : control 
4. In the Code area insert the code below and update as needed: 

//initiate gomezDate 

//calculate the depart and return dates 
var now =; 
var departDaysAhead = 30; //Change as needed, currently set to 30 days from the current date 
var returnDaysAhead = 7; //Change as needed, currently set to 7 days from the depart date set above 
var departDate = gomezDate.addDays(now, departDaysAhead); 
var returnDate = gomezDate.addDays(departDate, returnDaysAhead); 

//Date Formatting and Storing 
//If date is selected through drop down menus take this code 
var months = new Array('January ','February ','March ','April ','May ','June ','July ','August ','September ','October ','November ','December '); 
var departMonth = months[departDate.getMonth()]; 
var returnMonth = months[returnDate.getMonth()]; 

//stores the dates 
top.departMonth = departMonth; 
top.departDay = departDate.getDate(); 
top.returnMonth = returnMonth; 
top.returnDay = returnDate.getDate(); 

//If date is selected through a single input box take this code 
var departDate = gomezDate.printDate(departDate, '/', 'custom',['MM','S','DD','S','YY']); 
var returnDate = gomezDate.printDate(returnDate, '/', 'custom',['MM','S','DD','S','YY']); 
//returns the dates in this format MM/DD/YY, change as needed 

//stores the dates 
top.departDate = departDate; 
top.returnDate = returnDate; 

5. Save the script locally as a GSL or JSON file and open it in a text editor. 
6. Locate the action that needs the dynamic date.
7. Create a new line after the line of code with type in it .
If the type is selectOption insert the following code, change as needed 

"patch": "action.textValues[0] = top.departDay;", 

If the type is keystrokes, insert the following code, changing it as needed for your script:

"patch": "action.textValue = top.departDate;", 

An example of placement of the above line of code: 

"type": "selectOption", 
"patch": "action.textValues[0] = top.departDay;", 
"target": { 
"targetWindow": "gomez_top[0]", 
"locators": [["css", "#departureDay"], ["dom", "document.getElementById(\"departureDay\")"], ["css", "select[name=\"departureDay\"]"], ["dom", "document.forms[1][8]"], ["css", "div:contains(\"Are you flexible by +/- 1 day?\"):eq(8)"], ["css", "#flightsearchpod div:eq(7) select"]] 
"textValues": ["19"], 
"optionIndexes": [18] 

8. Repeat 6 and 7 as necessary. 
9. Save the file and open it in the Dynatrace Recorder.
10. Play back the script to verify that dynamic dates are being populated.

For more information about dates, see Date Functions and Using Dynamic Dates in the documentation.





  • No labels