XPath, Chrome and open in background tab

Using Chrome and XPath is pretty nice. Is it somehow possible to open these links in a background tab?

I have an XPath with xx1 is number from 1 to 10. Can I streamline this a bit without having 10 actions with a wait in between?

Yep, you can put the JavaScript that uses the XPath in a Repeat action loop from 1 to 10, and update a KM Variable to be the current loop index, then use that to set the KM Variable that contains the XPath.

You will need to CHANGE the JavaScript in Browser to Insert YOUR CODE that returns a URL plus a new line character ("\n").

Note that the below Macro/Script technically brings the new Chrome Tab to the front very briefly when it adds it. But then it quickly restores the original tab that was at the front.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


MACRO:   Using a Dynamic XPath in a Loop to Open Chrome Tabs in Background [Example]

-~~~ VER: 1.0    2020-03-11 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Using a Dynamic XPath in a Loop to Open Chrome Tabs in Background [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.




  • Using a Dynamic XPath in a Loop to Open Chrome Tabs in Background

==NOTICE: This macro/script is just an Example==

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.


  1. KM 8.0.2+
  2. macOS 10.12.6 (Sierra+)
  • Has NOT been tested in Catalina


  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    • ALL Actions that are shown in the magenta color
    • Set Variable “Local__XPath” to YOUR XPath. Be sure to properly place the KM Variable "Local__Index"
    • Execute JavaScript in Front Browser to use YOUR CODE that uses the XPath
      • Insert YOUR CODE that returns a URL plus a new line character ("\n")
    • ==For PRODUCTION, DISABLE the Action "Set URL List for Testing"==.


  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

1 Like

Hi Michael,

thanks for the macro. Just that I understand. I need to create another script that changes the XPath back to a regular link?

Like in this example: Copy the url address of the xPath

Yes. Follow that example. You will probably need to modify the JavaScript slightly to use the proper KM Variable.