Help anyone? Javascript for OpenERP


I am trying to work out how to get Keyboard Maestro to click in a specific field on the web client my business uses for shipping orders (OpenERP). I have made a command that uses the Focus Safari Field macro on our Delivery Orders page – in particular I would like the cursor to click in the ‘reference’ field. I am able to do this, but my problem is that the name of this field changes every time I open a fresh window.

For example, the Focus Field is called 'document.forms[0]["search_input_char_name_1074”]’

but if I then open another page with the same screen the name of the field changes to:


Peter has suggested writing some Javascript code to help find this field, but I’ve never had anything to do with Javascript so I don’t know how to do this. I was wondering, would some kind soul be able to help me out?



I think you can probably write an xpath expression to find that element.

If you

  • open a sample page in Chrome and right-click / ctrl-click the field, and
  • choose 'Inspect element'

You will be able to drill down through the expansion triangles in the elements view until you are selecting just your target element, and then

  • right-click / ctrl-click it
  • choose Copy XPath (Chrome only, Safari doesn't offer this form of copying)

and begin your understanding of XPath paths (a bit like file directory paths) by pasting what you have got into a text editor.

The automatically copied path will probably be a bit literal and absolute, and you may need to craft something a bit more general (perhaps, for example, allowing for the variations in that numeric suffix).

You can test and refine your XPath interactively with the ⌘F Find panel in Chrome or Safari elements view (both browsers accept XPaths as well as simple strings in their Elements views).

Once you have an XPath that reliably finds (and only finds) the element you want, you can use 'document.evaluate(strXPath)' in a KM 'Execute Javascript in Chrome|Safari' action.

You will find some examples of XPath use from KM in other threads in this forum. Most recently, I think:

PS depending on the page structure, might also be worth looking at document.querySelector()

Once you have got a js reference to the element that you need, either through .evaluate(xpath) or .querySelector(selectors), there are various ways of getting js to simulate a click event on it.


There's now a generic macro here: