1

I am trying to pass value to a calendar field using JavascriptExecutor in my Selenium code.

The method declaration is as follows:

public static void selectDepDate(WebDriver driver, String value) { js = (JavascriptExecutor) driver; js.executeScript("arguments[0].removeAttribute('readonly', 0)", deptDate); js.executeScript("arguments[0].value=''", deptDate); js.executeScript("arguments[0].value='" + value + "')", deptDate); } 

I am calling the method via selectDepDate(driver, "15-Sep-2020").

Upon execution of the script, I am seeing the following exception in the console logs:

Exception in thread "main" org.openqa.selenium.JavascriptException: javascript error: Unexpected token ')' 
2
  • At which line are you getting the error?CommentedSep 7, 2020 at 12:23
  • js.executeScript("arguments[0].value='" + value + "')", deptDate);
    – Bimlesh
    CommentedSep 7, 2020 at 14:44

1 Answer 1

1

Since you already have a reference to your webElement, You can use setAttribute with below approach to set the value.

 driver.executeScript("arguments[0].setAttribute(arguments[1], arguments[2]);", deptDate, attributeName, value); 

Here attributeName is the name of attribute to which you want to set date inside deptDate webElement.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.