potatout
potatout

Reputation: 187

send_keys to hidden elements

I want to send a text to a text box of a page.

Here is hidden element on page:

<textarea class="chatterTopicsEnabled groupAtMentionsEnabled publishertextarea" 
  id="publishereditablearea" 
  name="publishereditablearea" 
  role="textbox" tabindex="0" 
  title="Topics" type="text" wrap="soft" 
  data-uidsfdc="112" style="height: 208px;">Topics</textarea>
<input type="hidden" id="publisherprompttext" name="publisherprompttext" value="Topics">

My code by which i can click the text box but can do nothing to send text:

textbox = [tag for tag in driver.find_elements_by_tag_name('textarea') 
           if tag.get_attribute('name') == 'publishereditablearea']
textbox[0].click()
textbox[0].send_keys("text")

The error message said: element not visible.

How can I send a text to the textbox?

Upvotes: 2

Views: 4415

Answers (2)

Ratmir Asanov
Ratmir Asanov

Reputation: 6459

Try the following (it must work):

js = "document.getElementById('publishereditablearea').value = 'text';"
driver.execute_script(js)

Upvotes: 1

iamsankalp89
iamsankalp89

Reputation: 4739

Use like this using execute_script as your element is hidden

element=driver.find_element_by_id("publishereditablearea") 
driver.execute_script("arguments[0].click();", element)

Upvotes: 2

Related Questions