1

I was just fiddling around with slack. The slackbot sends different replies for "Hi". So I just wished to find out the various types of replies that it gives(using the programmer's way ;) ). For that I wrote this code in the console of my browser

var ft = document.getElementById("msg_input").getElementsByClassName("ql-editor")[0].getElementsByTagName("p")[0];
for(var i =0 ;i<10;i++)
{
    ft.innerHTML ="Hi";
    //some line of code that sends the above "Hi"

}

This code does the first part of what I want: "Hi" is inserted in the textbox(actually a paragraph). The second part is to send the message by pressing the enter key. And now I am stuck. I wish to press enter through the console and I have no idea of how to do this.

P.S. : The answer to the question here at How to submit a form using javascript does explain how to submit a form by adding the name attribute to the form and then document..submit(). But in my case, the form had no name attribute so I added one to it and then ran document..submit() but it actually reloaded the window with this error in the console

May-31 09:05:43.132 SOCKET-MANAGER (TAUM2F7AR) Closing socket because

4108: unexpected socket closure

I also tried the same with id of the form but even that didn't work.

The answer to the question Is it possible to simulate key press events programmatically also did not help.This is the code that I ran(Note event keycode is 13) and this is the screenshot of the result When I queried for the keycode (Note that it gives the keycode as 0). Moreover, I am using Firefox(and not Chrome) so I don't know why is it automatically gets changed to 0 even though I wrote 13.

Community
  • 1
  • 1
paradocslover
  • 2,932
  • 3
  • 18
  • 44
  • Possible duplicate of [How to submit a form using javascript?](https://stackoverflow.com/questions/9855656/how-to-submit-a-form-using-javascript) – Isaac May 30 '18 at 21:50
  • 1
    The slack web app presumably uses AJAX or websockets, not form submission. – Barmar May 30 '18 at 23:10
  • I have no idea about what it uses. But I definitely wish to know is it possible? Like is there a way out of it? – paradocslover May 31 '18 at 03:08

0 Answers0