I'm trying to enter text into a text box using python selenium.
The html looks like below:
<div class="sendBox placeholder" contenteditable="true" data-placeholder="Type a message or drop attachment..." id="sendMessage" style="height: 375px;"></div>
After manually typing 'TEST' into the text box, the html looks like this:
<div class="sendBox placeholder" contenteditable="true" data-placeholder="Type a message or drop attachment..." id="sendMessage" style="height: 375px;">TEST</div>
I've tried the following code, but there is no response
driver.find_element_by_xpath("//div[@id='sendMessage']").send_keys("testing")
However, if I manually click on the text box so that the cursor shows up and then enter in that code, it does work. I haven't been able to figure out how to make the curser show up via python selenium. I've tried the below though.
driver.find_element_by_xpath("//div[@id='sendMessage']").click()
It sounds like clicking and then sending keys to the element should help:
element = driver.find_element_by_xpath("//div[@id='sendMessage']")
element.click()
element.send_keys("testing")
You can also workaround it with setting the innerHTML via execute_script():
driver.execute_script("arguments[0].innerHTML = arguments[1];", element, "testing");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With