1

I like to fill out some forms in webpages automatically. E.g. https://www.dropbox.com . My problem: The value is set but not used when sending the form. Only if I use a real keypress the values are accepted and send.

Is that a kind to bot protection?

I am writting a Firefox Plugin that fills in my username and password.

In the picture you can see, using the script the values is in the background, the fieldname is still shown to me whereas using a real key press will enter the data correctly and allows to submit the input. jquery and keypress are failing: using my USB keyboard is working

Thanks in Advance!

Minimal Code: https://pastebin.com/7TZyKaMM

Key press code seems to be equal to real key press but does not influance element value whereas val('123') updates the value but does not sending a keypress.

It is still not working :-(

The goal is: entering a text as value using key press simulation.

Not working

User8461
  • 366
  • 2
  • 14
  • https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events you could try to dispatch a logical event – Taplar May 18 '20 at 20:36
  • Not working: `elSource.dispatchEvent(new KeyboardEvent("keypress", {key : "a", char : "a", shiftKey: false}));`, `$(elSource).focus().trigger(jQuery.Event('keypress', {which: 68}));`, with `'keydown'` or `keycode: 68`. I don't know, why that all not working. – User8461 May 18 '20 at 21:14
  • also not working: `$(elSource).val('123'); $(elSource).change();` – User8461 May 18 '20 at 21:15
  • Tried: https://stackoverflow.com/questions/14919459/using-jquery-to-listen-to-keydown-event , https://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript and https://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-safari-using-javascript - no success. – User8461 May 18 '20 at 21:16
  • Not working: https://stackoverflow.com/questions/11380634/simulate-enter-on-textarea-with-jquery-event-keydown-not-working and https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically/44190874 – User8461 May 18 '20 at 21:39

1 Answers1

1

It seems to be the answer:

 // set value
 $(elSource).val('123');
 $(elSource).change();

 // fire event
 var event = new Event('input', {
     bubbles: true,
     cancelable: true,
 });
 elSource.dispatchEvent(event);

https://pastebin.com/v1BmyGsE

User8461
  • 366
  • 2
  • 14