user5713018
user5713018

Reputation:

Python Selenium finds the input element but cannot send_keys

I am trying to write a string into an <input> element using Selenium web driver and Python in Windows.

The element it's located and selected, but the webdriver fails when trying to send_keys("mystring").

campotx = driver.find_element_by_css_selector("input.urEdf2TxtRadius.urEdf2TxtEnbl.urEdfVAlign")
campotx.click()
campotx.clear() 
##########----it works ok until here
campotx.send_keys("SM37")
campotx.send_keys(Keys.ENTER)

The issue is not related to the "find element" method: I tried by_ID, by_class_name and by_xpath. All of them are able to locate the element. I am only not able to send_keys.

I am using HTMLUNITS, the headless webdriver. The output error for this issue is rare, I tried googleing it but can't find anything:

selenium.common.exceptions.WebDriverException: Message: TypeError: Cannot call method "setOpenerRef" of null (http://myurl.com)

Here is the <input> source code:

<input id="ToolbarOkCode" ct="I" lsdata="{0:'ToolbarOkCode',1:'Command',4:200,13:'150px',23:true}" lsevents="{Change:[{ClientAction:'none'},{type:'TOOLBARINPUTFIELD'}],Enter:[{ClientAction:'submit',PrepareScript:'return\x20its.XControlSubmit\x28\x29\x3b',ResponseData:'delta',TransportMethod:'partial'},{Submit:'X',type:'TOOLBARINPUTFIELD'}]}" type="text" maxlength="200" tabindex="0" ti="0" title="Command" class="urEdf2TxtRadius urEdf2TxtEnbl urEdfVAlign" value="" autocomplete="on" autocorrect="off" name="ToolbarOkCode" style="width:150px;"/>

EDIT:

Upvotes: 2

Views: 1194

Answers (1)

user5713018
user5713018

Reputation:

I finally solved this by using javascript instead Selenium send_keys.

driver.execute_script("document.getElementById('ToolbarOkCode').setAttribute('value', 'SM37')")

Upvotes: 1

Related Questions