Leveraging the execute script command in Selenium IDE to determine the time duration between two dates displayed on the webpage

For work automation, I've been utilizing SIDE to streamline certain tasks. One challenge I'm facing involves extracting dates from a page using the store command and then attempting to calculate a duration using the execute script command, which should then be input in another section of the page. However, my current issue is that when running the script, the result shows NaN (Not a Number) instead of the calculated duration, leading to it being displayed as NaN in the designated box on the page.

In my Selenium IDE window, here's how things appear: Image showing stored variables and script

The script used with the execute script function is as follows:

const startDate = new Date(`${StartYear}`, `${StartMonth}` - 1, 1);
const endDate = new Date(`${EndYear}`, `${EndMonth}`, 1);     
const durationInMilliseconds = endDate.getTime() - startDate.getTime();    
const durationInYears = durationInMilliseconds / (1000 * 60 * 60 * 24 * 365.25);     
const roundedDuration = Math.round(durationInYears * 2) / 2;     
return `${roundedDuration}`;

After checking all inputs through echo (such as endmonth), they return the expected values. Using echo to verify scriptcito, however, results in NaN being displayed.

Despite seeking guidance from ChatGPT, the advice given assumes I am coding in Python myself rather than dealing directly with Selenium commands, causing issues with the process.

Answer №1

Here is a demonstration of how data can be transferred to the browser:

result = driver.execute_script('''
  let [firstMonth, firstYear, lastMonth, lastYear] = arguments
  const initialDate = new Date(firstYear, firstMonth - 1, 1)
  //... additional code will follow here
  return result
''', firstMonth, firstYear, lastMonth, lastYear)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for simulating mouse events in Jasmine tests for Angular 2 or 4

New to Jasmine testing, I'm exploring how to test a directive that handles mouse events such as mouse down, up, and move. My main query is regarding passing mouse coordinates from the Jasmine spec to my directive in order to simulate the mouse events ...

Customize your error messages in AJAX requests

The form on my index.php page submits to process.php, triggering the execution of the code below: $(document).ready(function() { $('#login_button').click(function() { event.preventDefault(); var formData = { 'email' ...

How can we convert props into state once they have been initialized using GetDerivedStateFromProps?

Presented here is a straightforward Component design: export default class Editor extends Component { constructor(props) { super(props); this.state = { field: "Some Initial Text" }; this.handleChangeField = this.handleChangeField.bind(this ...

What methods are available to test my website across different browsers such as outdated versions of Internet Explorer like IE8?

Currently, I am working on Chrome with Windows 7 OS installed. However, Windows 7 does not support Internet Explorer 8. This is causing issues when trying to view my web pages in the IE8 version and older. How can I resolve this problem? I have attempted ...

Press a specific button within a row displayed in a table

I have a table displayed below: <table id="tabmailveille"> <tr><td> <button onclick="return Ajax(162, {'idc': '125').value,'action': 'ajout'});"><img alt="Add" src="/Images/tableaux/add.pn ...

Issue with CORS Policy specifically in this scenario despite functioning properly for other assets

My API is built with Laravel and for the front-end, I am using Vue.js with Nuxt.js. I have successfully installed the CORS policy package, which is working well with all my other resources. However, I encountered an error for one of my features: ...

Comparing non-blocking setTimeout in JavaScript versus sleep in Ruby

One interesting aspect of JavaScript is that, being event-driven in nature, the setTimeout function does not block. Consider the following example: setTimeout(function(){ console.log('sleeping'); }, 10); console.log('prints first!!') ...

Establishing the maximum width of a Vuetify expansion panel component

https://i.sstatic.net/QqKVv.png I'm currently in the process of developing a webpage using vuetify and nuxt. My main focus right now is adjusting the max-width property of the expansion panel UI component (https://vuetifyjs.com/en/components/expansio ...

Can SVN hooks be incorporated into NPM in a way that is comparable to git hooks?

I want to incorporate an npm script that performs linting and testing before executing an svn commit. If there are any failures during the linting or tests, I want the commit process to halt, similar to a git commit hook. Does anyone have any recommendat ...

Pattern-Based jQuery Selectors

I am looking for a way to use jQuery to select all paragraphs < p > within a < div > that contain time stamps with the following formatting patterns: <p>[22:48]</p> or <p>[22:48 - Subject Line]</p> Can someone provi ...

Format a JSON file using clang-format

I'm facing an issue with my json file formatting. When I run clang-format on it, the output is ugly as it treats it like code. { "name" : "My great app", "description" : "It's really cool.", "version" : "0 ...

Extracting individual elements from an array with Node.js or JavaScript

let array1= [ "home/work/data.jpg", "home/work/abc.jpg", "home/work/doc/animal.pdf", "home/work/doc/fish_pdf.pdf" ]; array1= array1.map((data)=>{ return data.slice(2,data.length).join("/"); }); console.log(array1); i am trying to modify my array by re ...

Addressing the Summer Note Problem within a Bootstrap Popup

I am currently facing an issue with the functionality of the Summernote Text plugin in my project. The text inside the Summernote editor does not display what I am typing until I resize the browser window. Below is the code snippet for reference: <%-- ...

"Discover the power of D3.JS with three dazzling charts on a single page, plus a host of additional

As a student, I struggle with English and it makes me feel sorry and anxious... Despite that, I want to create three scatter plot charts on the same page using a single data file (csv). The dataset includes columns for Name, Height, Weight, and Grade (ra ...

"Trying to activate a hover effect on a div using JQuery, but it's not functioning

Is there a way to make these divs animate each time I hover over them? Currently, the animation only works once and does not repeat when hovering again. Can anyone provide guidance on how to achieve this? function Rotate() { $('#gear1,#gear2,#gea ...

Navigating through React Native - A guide to accessing the initial navigation state on React Navigation

Is it possible to retrieve the initial state in a similar format as what is provided by the onStateChange prop in NavigationContainer? Unfortunately, onStateChange does not run during the initial render. While I was successful in obtaining the state whil ...

Retrieving JSON Data using Fetch

My JSON file consists of a simple object containing 2 arrays: { "key1": ["a", "b", "c"], "key2": [ "d", "e", "f"] } When using JavaScript, I fetch the data and push it into an array to use it. const jsonData = '/things.json'; const myArray = ...

Mongodb will provide the previous collection

router.post('/orders/finish', function(req, res, next) { var order_id = req.body.order_id; var user_id = req.body.user_id; var table_id = ''; var result = []; mongo.connect(url, function(err, db) { assert.equal(null, err); ...

Experiencing problems with the calling convention in JavaScript

Here is a snapshot of the code provided: If the function testFields at Line:3 returns false, then the program correctly moves to Line:21 and returns the value as false. However, if testFields returns true, the program proceeds to Line:4, but instead of ex ...

Struggling to align images side by side using HTML and CSS along with figcaption and buttons

Adding buttons below images on my webpage is proving to be a bit challenging. I tried using the figcaption tag, but it resulted in the images stacking on top of each other instead of side by side. **My HTML:** <section class="mostpurch"> ...