I am trying to send text messages on whatsapp web version on chrome. (www.web.whatsapp.com)
This is the code:
document.getElementsByClassName("input")[1].innerHTML="This message was written via JS script! ";
var input = document.getElementsByClassName("icon btn-icon icon-send");
input[0].click();
But the problem is , initially when no text is present the input box looks like this:
And only when I physically write some text it changes to this:
And only now my script works since it requires the Send text button
.
I tried Jquery code to simulate keypresses at $('.input)by following function:
function pressKey() {
var e = jQuery.Event("keypress");
e.which = 32; // # space
$(".input").trigger(e)[1];
e.which = 91;
$(".input").trigger(e)[1];
e.which = 32; // # space
$(".input").trigger(e)[1];
e.which = 32; // # space
$(".input").trigger(e)[1];
}
It didn't work.
How can I get the Send text
button by script?
Here is the screen recording :
All options didn't work for me. Thats what I did.
function sendMessage(message) {
var evt = new Event('input', {
bubbles: true
});
var input = document.querySelector("div.input");
input.innerHTML = message;
input.dispatchEvent(evt);
document.querySelector(".icon-send").click();
}
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