I\'ve been on a prowl looking for a way to access a non visible text field using selenium\'s webdriver. The only way i got it to work is using
driver.execut
You need to obtain a JavaScript string representation of your Python variable's value, and insert that into your JavaScript command. Fortunately, Python's json module will do this for you.
from json import dumps
driver.execute_script("document.getElementById('text_field').value+=" +
dumps(my_python_variable))
I would be wary of just inserting the value into the quote marks as other answers have shown. What if the value already has quote marks in it, or special characters that need escaping? What if it's not a string at all? json.dumps will handle all the necessary formatting and escaping for you, appropriate to the type of your variable.