0

I'm unable to give values to a text field as below (it is leaving the field blank):

 browser.find_element_by_name("userId").clear()   
 browser.find_element_by_name("userId").send_keys('myname')

This is the html part of the text field im trying to give value:

<td align="left"> &nbsp;&nbsp;&nbsp;&nbsp; <input name="userCB" type="checkbox" onclick="disable_enable_user(checked)"/> User ID<br /></td>
<td align="left">
<input name="userId" type="text" size="15" value="" disabled="disabled">

Is it because the field is disabled, if so , how can I enable it?

1

1 Answer 1

0

You can set an attribute value of an element by using the JavascriptExecutor (the example is in JAVA but you can get the idea):

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('element id').setAttribute('attrName', 'value')");

In general, it's not a good practice to try to set a value to a disabled field (even by manipulation) if the goal is test automation. You should automate a form AS IS and look for workarounds only if:

  1. the "user flow" can't be automated otherwise
  2. this specific test is not important

hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

Hi , I am able to pass the value like browser.execute_script("document.getElementById('endDate_Year_ID').value = '2013'") but the values are not getting reflected finally. The default values are only picked

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.