send_keys to hidden elements

对着背影说爱祢 提交于 2021-02-10 14:01:28

问题


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?


回答1:


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)



回答2:


Try the following (it must work):

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


来源:https://stackoverflow.com/questions/47434202/send-keys-to-hidden-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!