Skip to content

Instantly share code, notes, and snippets.

@yask123
Created September 13, 2015 20:12
Show Gist options
  • Save yask123/6d15ce705ca33136c683 to your computer and use it in GitHub Desktop.
Save yask123/6d15ce705ca33136c683 to your computer and use it in GitHub Desktop.
function dispatch(target, eventType, char) {
var evt = document.createEvent("TextEvent");
evt.initTextEvent (eventType, true, true, window, char, 0, "en-US");
target.focus();
target.dispatchEvent(evt);
}
dispatch(document.querySelector("#compose-input div"), "textInput", "hello!");
function triggerClick() {
var event = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
document.querySelector(".icon.btn-icon.icon-send").dispatchEvent(event)
}
triggerClick()
@bbyiringiro
Copy link

it works on whatsaap web to automatically send message to someone i guess

@hemant47
Copy link

document.querySelector(".icon.btn-icon.icon-send") is not able to select the send icon on latest version.

@Aditya-Basak
Copy link

@hemant47 I found out that the button was renamed from "icon btn-icon icon-send" to "icon btn-icon icon-send send-container". Try it, that should work.

@VladIPlay
Copy link

Hello... i want to send allways when the minutes are 00 a message... how i can do it?
is this the right way?
.................................
var d = new Date();
var n = d.getMinutes();
if(n == 0){
document.getElementsByClassName("input")[1].innerHTML="Fiix";
var input = document.getElementsByClassName("icon btn-icon icon-send send-container");
input[0].click();
}
.......................................

@vince-lynch
Copy link

I'm surprised anyone can get this to work, for me document/window is not defined in whatsapp web. I cant select the elements .click() on them. Even with Xpath, I can select on elements when a chat window is already open, but I can't get javascript to click on an avatar to open up one of those chats? am I wrong?

@vijayran111
Copy link

tried kinda everything , can someone tell me the step by step process for mac please.

@gokunambiar
Copy link

How to modify this so that I can send same whatsapp message to multiple contacts based on their name or mobile no? Pls help

@QinisoM
Copy link

QinisoM commented Jan 2, 2017

As per @gokunambiar. Is there a way to trigger a sele/click on an item in the chat list on the left panel?

@diogosimao
Copy link

Hi! How might I integrate this code with WhatsApp API feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment