如何使用Selenium和Python将文本插入div节点 [英] How to insert a text into a div node using Selenium and Python
本文介绍了如何使用Selenium和Python将文本插入div节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用硒将文本放入div().我使用python并将javascript插入我的代码中.这是我的代码:
I want to put a text into div () by using selenium. I use python and insert javascript into my code. Here is my code :
js="document.getElementsByClassName(\"inputPanel\")[0].innerText=\"hello!\";"
但是它提醒我有一个错误:
But It remind me there is a mistake:
selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot set property 'innerText' of undefined
我该如何解决这个问题?如果可以的话,我将不胜感激!
how can I solve this problem? If you can help, I would appreciate it !!
推荐答案
要将字符序列插入<div>
节点,可以使用以下解决方案:
To insert a character sequence into a <div>
node you can use the following solution:
my_desired_text = "lzylzylzy"
driver.execute_script("document.getElementsByClassName('inputPanel')[0].innerHTML="+ my_desired_text)
这篇关于如何使用Selenium和Python将文本插入div节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文