python - 如何通过 Selenium 和 Python 根据 html 将文本发送到 textarea
问题描述
我想在文本框中单击并发送文本,但找不到该元素。
这是我要单击并发送文本的 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 - Ansible:无法设置 vars 变量
- angular - 在描述调用中获取夹具和组件值 - Angular 单元测试
- fullcalendar - Fullcalendar:更改 startParam / endParam 键的名称
- python - 为什么 os.linesep 仅适用于 Python 中的某些字符串?
- sql - 从 Oracle 到工作簿的 SPOOL 数据
- c++ - 不能调用函数参考c++
- java - 如何在 Kafka 中使用多线程
- angular - SharedModule 导出的未使用模块会影响 Angular 应用程序的性能吗?
- android - 安卓屏压支持
- perl - Getting Blank Screen for Perl CGI Script