0

I'm not an expert in Javascript but I have a task: I need to paste a search query in Google search and then press Enter key using only Javascript.

I paste a search query like this:

document.querySelectorAll("input")[4].value="Cat"

How can I simulate Enter key press?

I know that I can paste using:

document.location.href = 'https://www.google.ru/search?q=Cat';

But this solution is not suitable for me because I do not work with Google, but my problem is similar that I described. Plus I use Android WebViev (Chromium) and it does not support JQuery.

Delphian
  • 1,650
  • 3
  • 15
  • 31
  • The main purpose of my question is how to simulate Enter key press using Javascript. Google here for an example – Delphian Feb 03 '17 at 12:26
  • _“But this solution is not suitable for me”_ – care to explain why? // If you can fill a form field on the original Google page, then you can probably submit the form via JS as well (and that is easier than trying to simulate a key press.) – CBroe Feb 03 '17 at 12:32
  • Because I do not work with Google, but my problem is similar that I described. Plus I use Android WebViev (Chromium) and it does not support JQuery. – Delphian Feb 03 '17 at 12:38
  • I can’t see why jQuery would not work in a webview (you have to embed it first, of course) - but luckily, something as trivial as submitting a form via JS does not need jQuery. – CBroe Feb 03 '17 at 14:47
  • I try to use methods from this thread but it doesn't work - http://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programatically – Delphian Feb 03 '17 at 15:33
  • Why are you even trying to do it that way? What is the problem with just submitting the form using vanilla JavaScript? If you are able to use that already to populate a form field, then I really don't see where the issue is? – CBroe Feb 04 '17 at 14:26
  • Also, I can't understand why do not work. It might be an ajax request. – Delphian Feb 06 '17 at 13:15

0 Answers0