gpt4 book ai didi

python - send_keys 到隐藏元素

转载 作者:太空宇宙 更新时间:2023-11-04 00:25:59 26 4
gpt4 key购买 nike

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

这是页面上的隐藏元素:

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

我可以点击文本框但无法发送文本的代码:

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

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

如何向文本框发送文本?

最佳答案

像这样使用 execute_script 因为你的元素是隐藏的

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

关于python - send_keys 到隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47434202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com