pghilb has asked for the wisdom of the Perl Monks concerning the following question:

One particularly nasty <input> node $i, on a webpage I am trying to automate, accepts the necessary value sent via WWW::Mechanize::Firefox,

but when a button, invoking the action in which the above input is needed, is clicked, the webpage complains that no value was entered.

Apparently, some internal JS-script does not give its approval on the value, and the page isn't modified accordingly. I tried to imitate this, prior-to-clicking, modification, but didn't succeed in that either.

When I submit the value manually, the page is modified as it should (surprise, surprise), whenever the value is assigned after hitting the EnterKey. So my question is whether it is possible to imitate hitting the EnterKey, or any other important events (apart from realized onClick) in WWW::Mechanize::Firefox? Any input will be greatly appreciated.

Replies are listed 'Best First'.
Re: W-M-F and event.keyCode===keys.ENTER
by Corion (Pope) on Jul 27, 2014 at 08:36 UTC

    WWW::Mechanize::Firefox doesn't have any premade solution for this, but if you look at MozRepl::RemoteObject, each element gets the __event() method from there, which is a wrapper for sending JS events.

    The code only provides for mouse events, so most likely you'll have to modify the Javascript to also generate keyboard events there.

      Thank you very much indeed, Corion! Managed to solve the problem along the lines you've suggested.

      The situation is rather standard nowadays, with all these autofillers, etc. which makes the straight assigning of values impossible.

        Note that WWW::Mechanize::Firefox already sends focus and blur events if you use the ->field() method to set the value.

Re: W-M-F and event.keyCode===keys.ENTER
by Anonymous Monk on Jul 27, 2014 at 03:28 UTC

    sure, load jquery, trigger keypress on your target event,

    If you can read the source of jquery you can figure out how to do it without jquery

      Thanks, will try that! Managed to solve the problem with MozRepl::RemoteObject, following Corion's advice and the hint given in the module's documentation:
      $i->__event('focus'); # $i = the input I am working with $i->{value}='xyz'; $i->__event('blur');