lzy
lzy

Reputation: 57

How to insert a text into a div node using Selenium and Python

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

Answers (2)

undetected Selenium
undetected Selenium

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

Waqar Nadir
Waqar Nadir

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

Related Questions