1

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 !!

3
  • Add your code here, not an image of it. Commented Mar 14, 2019 at 7:51
  • Just remove the dot "." before .inputPanel Commented Mar 14, 2019 at 7:51
  • Please paste the code here, in a formatted way. meta.stackoverflow.com/questions/251361/… Commented Mar 14, 2019 at 7:53

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

6 Comments

but i still get this warning @DebanjanB
it said my desired text is not defined,i wonder if you can help me further.thank you@DebanjanB
@Izy my_desired_text is a variable which you can assign with any text. I have updated my answer. Let me know if you need further help.
thank you for your further help ! yeah ,i know what you mean,i replaced my_desired_text with string before.and also i used your answer to replace my code.But it still warn me like this:selenium.common.exceptions.WebDriverException: Message: unknown error: lzylzylzy is not defined . i thought maybe it is not a grammar mistake.@DebanjanB
i only know that we usually use <input> to upload string.but this time i find that <div> is editable.i want to upload a string into it .the webpage source code is like this: <div contenteditable="true" class="inputPanel" style="height: 83px; outline: 0px; border: 0px; overflow: hidden auto; font-size: 14px; line-height: 18px; width: 100%; resize: none;"></div>. would you please give me some suggestion to solve this problem? @DebanjanB
|
1

Remove . placed before inputPanel and also there is no end tag of [

Expected Code will be

document.getElementsByClassName(\"inputPanel\")[0].innerText=\"hello!\";"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.