5

I'm trying to automate the selection of items (using jQuery) from the autocomplete dropdown of the google maps api v3 places library. I am unable to determine the javascript required to select the item from the dropdown.

So, for example, here are the steps required to complete a partial field and trigger the dropdown for something like google's demo of this resource:

[EDIT the following code updated to show solution...]

$('input[name=address]').val("525 Bergen Street");
$('input[name=address]').trigger("focus");
$('input[name=address]').simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
$('input[name=address]').simulate("keydown", { keyCode: $.ui.keyCode.ENTER });

[EDIT...see Engineer's reference to simulate, below.]

Any suggestions would be greatly appreciated, thanks,

Lille

Lille
  • 305
  • 4
  • 14
  • You want to go the result of a specific query without typing or clicking something? – Ersel Aker Apr 08 '12 at 12:21
  • Yes, I'm automating these steps in a web app integration test framework that allows me to execute javascript code, such as that shown above. What I'm missing is adequate knowledge of the events that I would need to trigger on the google maps api v3 places autocomplete dropdown (BTW -- at this point I'm indifferent between simulating the goal 1) with downkey and enter or 2) mouse actions). – Lille Apr 08 '12 at 12:46

1 Answers1

4

Try to use jquery.simulate.js :

$(elem).simulate(mouse_or_keyboard_event_type, options);

Supported event types:

  • mouse: mouseover, mouseout, mousedown, mouseup, mousemove, click, dblclick
  • keyboard: keyup, keydown, keypress
Engineer
  • 47,849
  • 12
  • 88
  • 91
  • This might be useful once I know what events trigger the desired result, namely, selection of an item from the google maps api v3 places autocomplete dropdown, but otherwise, it seems to me it will just duplicate my guesswork so far in jQuery. – Lille Apr 09 '12 at 00:06
  • Engineer's recommendation to use jquery.simulate.js eventually got me what I needed. I would recommend this tool and using the 'key' event simulations for anybody scratching their head over an autocomplete task. – Lille Apr 10 '12 at 02:06