Using javascript from python to set the value of a hidden input
<p>I'm converting an automated test case to use IE rather than FireFox. The case worked fine on Firefox, however I've found IE has a very strange behavior. It's duplicating the input for login credentials and hiding the input that I need to access. (Note this is IE doing it, not the source for the application I'm testing)</p>

<p>I'm using Selenium and Python, and I need to pass the login credentials to the hidden input fields. I'm aware that you cannot access hidden fields in Selenium, however I've seen a lot of SO posts saying you could do it with Javascript. Which brings me to my question. What am I doing wrong here? I'm not very familiar with Javascript, but everything I've seen so far indicates that this should work. </p>

<p><strong>My Python:</strong> (Key is a parameter for the script)</p>

<p><code>driver.execute_script("document.getElementsByClassName('form-control placeholder').setAttribute('value', '" + key + "')")</code></p>

<p><a href="http://i.stack.imgur.com/1cTKF.png" rel="nofollow">IE Page Source</a></p>

<p><a href="http://i.stack.imgur.com/LdsH0.png" rel="nofollow">IE Error</a></p>

<p>The method getElementsByClassName returns an array so, you should try:
driver.execute_script("document.getElementsByClassName('form-control placeholder')[0].setAttribute('value', '" + key + "')")</p>

javascript python selenium-webdriver