0

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

Date Picker: enter image description here

la1
  • 519
  • 1
  • 8
  • 30
  • 1
    can you share url of calender so that I can work check elements – Justin Lambert Sep 04 '20 at 06:11
  • Thanks for the reply. I have updated the Question with more details, able to set the value now and value shows on the UI too but in HTML value is empty (.getAttribute(value) O/P correct value) however when clicked the Submit button, this field shows it is mandatory though the value can be seen. – la1 Sep 04 '20 at 07:48
  • 1
    I am not sure why value is getting empty. However solved similar issue of selecting date by clicking on calendar icon and then clicking on date. Similarly you need to modify script to choose months and year if you dont wish to one open by default : https://stackoverflow.com/questions/63549816/locate-element-with-selenium-xpath-for-date-picker-drop-down-menu-in-python/63556700#63556700 – rahul rai Sep 04 '20 at 08:08
  • Thanks for guiding, however the date picker elements are not under td/tr elements nor in iFrames, nor will be able to click on the Month/year field. Unless clicking < > symbols will not be able to move. We are reading Date value from other file hence trying to insert date than clicking the Date picker. – la1 Sep 04 '20 at 08:56

0 Answers0