Given:
<input class="inputField_input__2B0dA" maxlength="7" id="establishedYear" data-testid="date-input" type="month" value="">
Which on the page is an input field that looks like : ----- ---- [Calendar symbol]
The frist ----- resemble the month, and the next ---- the year => April 2020
But the only way to select the actual date is by clicking on the calendar and clicking on a month
I tried to write the value of the element with the required string using js:
// JavascriptExecutor jse = (JavascriptExecutor) getDriver();
// jse.executeScript("document.getElementById('establishedYear').setAttribute('value', '2022-04')");
Which works until the next action, when i click on another element, the value set with JS dissapears.
PS. If i try to manually type the date, it would work for the month, but then for the date if fails, it only changes the last char like for 2022 it would type 0002
Also, If i try to bascially click on the calendar icon, then click on the month with selenium, I cant do that because, when I try to create a selector for the date elements from the caledar, I cannot find them on the DOM.
So i click on the calendar icon, no changes to the dom appear(no new elements added to the dom)
Any suggestions on how to tackle this problem?
Solved this by:
ocupSelfEmpPage.establishedYearInput.click();
ocupSelfEmpPage.establishedYearInput.sendKeys(Keys.SPACE);
ocupSelfEmpPage.establishedYearInput.sendKeys(Keys.UP);
ocupSelfEmpPage.establishedYearInput.sendKeys(Keys.ENTER);
So clicking on the input, then space to open the calendar and up to select january, then enter to save it