Choosing a specific date from an input field of type 'month'

Given:

<input class="inputField_input__2B0dA" maxlength="7" id="establishedYear" data-testid="date-input" type="month" value="">

This input field on the page resembles a date format: ----- ---- [Calendar symbol]

The first set of dashes represents the month, and the second set represents the year => April 2020

However, the only way to select the actual date is by interacting with the calendar icon.

I attempted to set the value of the element programmatically using JavaScript:

//        JavascriptExecutor jse = (JavascriptExecutor) getDriver();
//        jse.executeScript("document.getElementById('establishedYear').setAttribute('value', '2022-04')");

This works initially, but as soon as I interact with another element, the value set with JS disappears.

Furthermore, manually typing the date leads to issues where entering the year results in only the last character being registered. For example, if trying to type 2022, it would show up as 0002.

Additionally, attempting to automate the selection process by clicking on the calendar icon and then selecting the month using Selenium proves challenging because the date elements are not found in the DOM.

Even after clicking on the calendar icon, no changes to the DOM occur (no new elements added).

Any suggestions on how to address this issue effectively?

Answer №1

Resolved the issue by executing the following steps:

    clicking on the specified input element,
    triggering a space key press to open the calendar,
    using the up arrow key to select January,
    pressing enter to confirm and save the selection.

This sequence effectively activates the date picker, navigates to January, and finalizes the chosen date.

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

The session cannot be created due to a lack of compatible capabilities between Selenium version 3.14.0 and GeckoDriver version 0.23.0

I have selenium-java-3.14.0 and geckodriver-v0.23.0-win64 installed, and I'm running the code below. WebDriver driver; System.setProperty("webdriver.gecko.driver", "D:\\\\Try out files\\\\geckodriver.exe"); dri ...

Discover the best locations within the city using Google's API to search by category

Users will choose a city and a type of place. The desired output is a Google Map showing all places in that city with the selected category. I'm looking to achieve this using Google Maps APIs. So far, I've tried using the Places API but it onl ...

Convert the first child of the element with the id "images" into a string using document.getElementById("images").children

When using the toString() method, it will display [object HTMLImageElement]. My goal is to get a string representation of the image element '<img src="..." />'. However, in Firefox, outerHTML returns undefined. Is there another way I can a ...

Clicking on checkboxes using jQuery

Here is my current code snippet and the task I am currently working on. The objective is to check the corresponding checkbox if json[i].enabled is true, and leave it empty if not. function createTable(json) { var element = ""; var i; ...

Errors encountered while running `npm install discord.js`

I am currently facing an issue while trying to install discord.js. Unfortunately, I keep encountering the following errors: npm ERR! cb() never called! npm ERR! This is an error with npm itself. Please report this error at: npm ERR! <https://npm.co ...

Dynamic value updates using jQuery input type formulas

I need help with a form that has two inputs: The first input allows the user to enter an amount, such as 1000. The second input is read-only and should display the value of the first input plus 1%. For example, if the user types in 1000 in the first fie ...

Displaying the Selected Value from the DropDown in the Menu

I am working with Bootstrap5 and have the following dropdown menu in my code. Instead of displaying "Year," I would like to show which member was selected. How can I achieve this? <div class="dropdown"> <button class="btn btn- ...

Utilizing AngularJS for toggling data with ng-click

In my project, I have a unique issue with a list item that toggles a modal and sets a parameter using ng-click. Strangely, when calling a specific function in another location, Course.SelectedCourse returns as undefined, even though Course.ID has a valid ...

How do you find the value of a variable in IE 9 debugger?

Having an issue with my code on IE 9, it works fine in Firefox: var denomAmount = j(this).closest('.denom').children('.denomValue').eq(0).val(); I'm trying to understand what eq(0) will return, but the IE9 debugger is not providi ...

Is there a way to confirm that every item in a list falls within a specified range?

I'm attempting to compare elements in a list with the locator value of 70.000. I have tried using AssertJ for this comparison, but unfortunately it's not working as expected: List<WebElement> priceList = driver.findElements(By.className(" ...

Python/Selenium Firefox Driver Functions flawlessly on Windows but encounters issues on Ubuntu

I am facing some challenges with my setup on Ubuntu (Amazon EC2 t2.small), which includes the following components: geckodriver: 0.24.0 firefox: 68.0.1 selenium: 3.141.0 On my Windows system, I have: geckodriver: 0.24.0 firefox: 67.0.4 selenium: 3.141.0 ...

displaying outcomes as 'Indefinite' rather than the anticipated result in the input field

I need to automatically populate values into 4 text fields based on the input value entered by the user. When the user exits the input field, a function called getcredentials() is triggered. This function, in turn, executes Python code that retrieves the r ...

My goal is to create a JavaScript application that functions as a basic counting tool

I've encountered an issue with my simple counter code - it's not functioning properly. The goal is for the decrement function to stop running when the count reaches 0. I'd appreciate any help in troubleshooting what might be wrong. let count ...

What is the top choice instead of using the jQuery toggle() method?

After jQuery deprecated the toggle() method, I began searching for alternative ways to toggle classes on Stack Overflow. I came across various other methods to accomplish the same task (Alternative to jQuery's .toggle() method that supports eventData? ...

javascript implementation of jquery1.3.2 plugin for creating a marquee

Hi everyone, I'm facing a situation where I need to show horizontally scrolling text moving from left without using the marquee tag. The solution should involve only the jquery1.3.2.min.js plugin. Please assist me with this task. Thank you in advance ...

The console is showing messages before the task is completed

When using console.log to write detailed messages about the current task expected to be performed by Protractor, I noticed that these messages are appearing on the console before the actual task is executed in the browser. An example of this is: it(' ...

Store the outcome in a JSON file while utilizing a post request with AJAX and Node.js

In my current project, I am developing a JavaScript code to track the system configuration of users, such as screen resolution statistics. Initially, I created an AJAX file to collect the data in object form and utilized node.js to handle the request and s ...

Transmit the map via res.send in Express

My friend and I are collaborating on a game project, but we're encountering an issue when trying to send a Map with some data in it. Instead of receiving the actual Map, Express is sending the user {}. Strangely enough, when I use console.log to check ...

Creating routes in JavaScript to split an object like a tree: a comprehensive guide

When I receive a set of filters as a composed object in my express server, I realized that to create the query I need to split each object route into a separate array of keys. For example: $and: { age: [21, 22], name: { $like: "Alice& ...

Navigating the tangled web of directive scopes: steering clear of endless $parent chaining for accessing variables

After referencing the "How to create directives that communicate" section in the angularJS guide, I decided to apply that concept to develop a navigable form. The challenge arose when attempting to access the main scope to input data from the form fields ...