2

We are testing a ASPNET MVC Application by using Selenium.

In the Webpage they are using a Jquery Date control Textbox datepicker/#icon-trigger and that text box was in Disable mode

I am trying to send the values from selenium to webpage by using following code.

    Driver.findElement(By.id("txtDOB")).sendKeys("10/10/1986");

But it was not working. it doesn't show any error.

and Now My question is how to send values to Disabled text box?

Can any one help me on this...?

1
  • The answer is: Don't. It's extremely bad test logic to perform actions that a user can't do (another example would be to set a hidden input value.) Commented Dec 19, 2013 at 20:22

2 Answers 2

2

Well you have two approaches here

  1. Do it like a user would do and use the query date picker see here (untested)
  2. Enable the text box and then set the field something like this:

    WebElement textbox = driver.findElement(By.id("xxx"));
    ((JavascriptExecutor) driver).executeScript("arguments[0].enabled = true", textbox); 
    
Sign up to request clarification or add additional context in comments.

1 Comment

i have already try this code. I enable the textbox and then try sendkeys.. but no luck.. is there any other way..?
0

I would really recommend that you script this so that it uses the date picker, in the exact same way a user would have to pick a date, as the user is not allowed to type in their own date.

If really must work around this, then you could try forcing a value into the textbox using javascript:

IWebElement textbox = driver.findElement(By.id("txtDOB")); 
((JavascriptExecutor)driver).executeScript("arguments[0].value='10/10/1986'", textbox);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.