1

I am automating a web application which has multiple date pickers in them. I am sending values in them by using javascriptExecutor.

IJavaScriptExecutor js = (IJavaScript)driver; 
string jscript = (string)js.ExecuteScript("document.getElementById('formSIES:cFechaIniSintomas_input').removeAttribute('readonly',0);");   

The problem is that my code does not work in all my date pickers. I have tried with another script

IJavaScriptExecutor js = (IJavaScript)driver; 
string jscript = (string)js.ExecuteScript(document.getElementById('formSIES:cFechaIniSintomas_input').setAttribute('value','11/12/2018'););

I went over the format and it is correct. Please check.

  • 1
    Can you post the error(s) that you are seeing? As it is, your code is a bit too nebulous to help you effectively. – Brian Feb 15 '19 at 19:46
  • I just use sendkeys - when testing, usually the point is to test the overal function of the process, not the already developer unit-tested (a billion times) datepicker itself. – Bill Hileman Feb 15 '19 at 20:11
  • Technically I am not having a problem, but the value send by my date picker is not the one I am sending in the JavascriptExecutor. It picks today's date instead of my value – Sergio Feb 15 '19 at 20:30
  • Could share the HTML of the datepicker? Probably is more reliable to simulate the user interaction, such as finding the date using findElement based on a string. – João Farias Feb 16 '19 at 10:26
0

You can try this

String dateval = "28/03/2019";

selectDatebyJs(driver, date1, dateval); }

public void selectDatebyJs(WebDriver driver,WebElement element, String dateval) throws InterruptedException {

JavascriptExecutor js = ((JavascriptExecutor) driver); js.executeScript("arguments[0].setAttribute('value','"+dateval+"');", element); WebElement date2= driver.findElement(By.id("yourId"));

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.