We have non writable Date field for which value can be selected clicking Date Picker icon. Below is the HTML code:
<input aria-in="false" type="text" testid="cut-value" class="MuiInputBase-input Test-input MuiInputBase-inputAEnd" value="" style="padding: 14px;">
When clicked Date picker and manually or through Selenium click the Date picker icon and select the Date, works fine. After setting manually the HTML code changes as below (value attribute shows with value selected).
<input aria-in="false" type="text" testid="cut-value" class="MuiInputBase-input Test-input MuiInputBase-inputAEnd" value="03 Sep 2020" style="padding: 14px;">
However trying to set the value rather clicking on the Date picker since need to Set specific Date here. Tried below code, no exception or error thrown with this, however Date is not set. Tried .sendKeys too, didn't work.
System.out.println("visible: "+ ele.isEnabled() + ", " + ele.isDisplayed());//O/P is true, true
WebElement ele = driver.findElement(By.xpath("//input[@testid='cut-value']"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].setAttribute('value',\"01 Sep 2020\")",ele);
UPDATING The Issue: With the below script, able to set the value and value shows on in this field however in HTML the value attribute is empty.
((JavascriptExecutor)driver).executeScript("arguments[0].value=arguments[1]",
driver.findElement(By.xpath("//input[@testid='cue-value']")), "01/09/2020");
On the UI value shows as: 01/09/2020 but in HTML it is empty due to this when saved the record, throws as this field is mandatory though value is present.
value=""
Referred below posts too:
How to use javascript to set attribute of selected web element using selenium Webdriver using java?
Need help for webdriver and Javascript for a hidden File upload element