我想在文本框中单击并发送文本,但无法找到该元素。
这是我想要点击并发送文本的 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/