Reputation: 57
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 !!
Upvotes: 1
Views: 1997
Reputation: 193108
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)
Upvotes: 1
Reputation: 388
Remove . placed before inputPanel and also there is no end tag of [
Expected Code will be
document.getElementsByClassName(\"inputPanel\")[0].innerText=\"hello!\";"
Upvotes: 1