python - 如何通过 Selenium 和 Python 将文本按照 html 发送到文本区域

标签 python selenium xpath css-selectors webdriver

我想在文本框中单击并发送文本,但无法找到该元素。

这是我想要点击并发送文本的 html-

<form class="addComment expand" data-id="9656414">
<img 
src="https://ctl.s6img.com/society6/img/g2taHIrokQ01R_67jS8ulaWI2wk/h_150,w_150/users/avatar/~artwork/s6-original-art-uploads/society6/uploads/u/sul97/avatar_asset/d837ee10016843a3bba9ae3310cc338d" width="25" height="25">
                                <textarea placeholder="Add a comment..." data-button="9656414"></textarea>
                                <button id="b9656414">Comment</button>
                            </form>

我的代码:-

driver.find_element_by_class_name('add').click()
comments = driver.find_element_by_xpath("/html/body/form[2]")
comments.click()
comments.send_keys("Awesome Art")

我可以点击,但无法在上面输入文字。我做错了什么?

最佳答案

如果您想在文本区域输入文本,您需要找到文本区域:

driver.find_element_by_xpath("//textarea[@data-button='9656414']")

关于python - 如何通过 Selenium 和 Python 将文本按照 html 发送到文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52177780/

相关文章:

perl - 为什么 find_child_elements 忽略 Perl Selenium 中的第一个参数?

xml - 遍历子节点

python - 将变量从 Jupyter notebook 传递到 python 脚本

python - 使用 twisted.conch 跟踪 ssh 登录尝试的 IP

python - 在 Python 类的装饰器函数中访问 self

python的日期时间和月末

html - 仅选择 div 内部的文本

selenium - 如何使用 Python 填写 JavaScript 表单?

java - 如何在一串数字中添加前导零以使其成为所需的 9 位数字

java - 对于参数类型 int、String,运算符 < 未定义