2

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?

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
potatout
  • 187
  • 1
  • 11

2 Answers2

2

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)
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
1

Try the following (it must work):

js = "document.getElementById('publishereditablearea').value = 'text';"
driver.execute_script(js)
Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • hi, i have tried this code on my end, but it does not work well. The text has not been inserted into text box. – potatout Nov 24 '17 at 03:29
  • @YamPakChing, any other error message? Because it's working for me. – Ratmir Asanov Nov 24 '17 at 10:27
  • There is no error for this code, but no output came from this code. and i have added new code of html. i am sure i could click the text box but do nothing for sending text – potatout Nov 24 '17 at 10:41
  • @YamPakChing, after my code you need to save your results. Is this not working? – Ratmir Asanov Dec 31 '17 at 11:25
  • @YamPakChing, also you can try like this: `js = "document.getElementById('publishereditablearea').innerHTML = 'text';"`. Let me know about results. – Ratmir Asanov Dec 31 '17 at 11:28