image of code using inspector
I want to click new chat button in / , and search a string.
Below is html tag that i want click:
<button class="icon icon-chat" title="New chat"></button>
and i use this javascript to click it:
document.querySelector('.icon.icon-chat').click()
but not work.
in same web, i use this code for clicking sending icon for send message and work:
document.querySelector('.icon.icon-sendpose-btn-send').click()
image of code using inspector
I want to click new chat button in http://web.whatsapp./ , and search a string.
Below is html tag that i want click:
<button class="icon icon-chat" title="New chat"></button>
and i use this javascript to click it:
document.querySelector('.icon.icon-chat').click()
but not work.
in same web, i use this code for clicking sending icon for send message and work:
document.querySelector('.icon.icon-send.pose-btn-send').click()
Share
Improve this question
edited Jun 7, 2017 at 3:34
Tutik Masfiyah
asked Jun 7, 2017 at 3:18
Tutik MasfiyahTutik Masfiyah
833 silver badges8 bronze badges
0
2 Answers
Reset to default 10The React dev tools shows that the event handler is written to trigger on mousedown. So you have to fire mousedown event
Type this in console
function simulateMouseEvents(element, eventName) {
var mouseEvent= document.createEvent ('MouseEvents');
mouseEvent.initEvent (eventName, true, true);
element.dispatchEvent (mouseEvent);
}
simulateMouseEvents(document.querySelector('.icon.icon-chat'), 'mousedown')
Try this one
function triggerMouseEvent(node, eventType) {
var event = document.createEvent('MouseEvents');
event.initEvent(eventType, true, true);
node.dispatchEvent(event);
}
triggerMouseEvent(document.getElementsByClassName("chat-title")[0], "mousedown");