I was trying to input values to react date (exactly same Calendar like https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_date) and time(exactly same time like https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_time)
var dateInput = await this.driver.findElement(By.xpath(addIncidentDateObject.incidentDate));
await this.driver.wait(until.elementIsVisible(dateInput));
await this.driver.executeScript('arguments[0].focus();', dateInput);
await this.driver.sleep(2000);
await this.driver.executeScript("arguments[0].setAttribute('autocomplete', 'off');", dateInput);
await this.driver.executeScript("arguments[0].setAttribute('autocorrect', 'off');", dateInput);
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('input', { bubbles: true }));", dateInput);
await this.driver.executeScript("dateInput.setAttribute('value', 'Nov 01, 2023')", "");
await this.driver.sleep(2000);
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('change'));", dateInput);
var dateInput2 = await this.driver.findElement(By.xpath(addIncidentDateObject.incidentDate2));
await this.driver.executeScript('arguments[0].focus();', dateInput2);
await this.driver.executeScript(`arguments[0].setAttribute('value', '2023-11-01')`, dateInput2);
await this.driver.sleep(1000);
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('change'));", dateInput2);
var elmentXpath = await this.driver.findElement(By.xpath("//div[contains(text(),'Title')]/following-sibling::input"));
await this.driver.executeScript("arguments[0].dispatchEvent(new Event('change'));", elmentXpath);
await this.driver.sleep(3000);
This is my code. date - html code If I am adding date or time manually, value attribute of both input field is updating automatically. time - html code The above code inputting value to the corresponding field but after that if I try to input any value to any another field in the page clearing this value. Xpath of both input fields of date
I tried to update the value attribute of both input fields. While it successfully updates and displays the value in the UI, another input event clears this value.