send_keys到隐藏的元素 [英] send_keys to hidden elements

查看:69
本文介绍了send_keys到隐藏的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文本发送到页面的文本框中.

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")

错误消息说:元素不可见.

如何将文本发送到文本框?

How can I send a text to the textbox?

推荐答案

由于隐藏了元素,因此使用 execute_script 这样使用

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)

这篇关于send_keys到隐藏的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆