function getDOMPath(node, dontGoUpTheDom /* = false */) {
    var path = [],
      entry = "";

    if (node === window) {
      return "window";
    }

    while (node instanceof Node) {
      // div
      entry = node.nodeName.toLowerCase();

      // shorten the path a bit
      if (["body", "head", "html"].indexOf(entry) > -1) {
        path.push(entry);
        break;
      }

      if (node instanceof DocumentFragment) {
        entry = "DocumentFragment";
      }

      // div#foo
      if (node.id && node.id !== "") {
        entry += "#" + node.id;
      }
      // div#foo.bar.test
      else if (typeof node.className === "string" && node.className !== "") {
        entry += "." + node.className.trim().replace(/\s+/g, ".");
      }
      // div[0] <- index of child node
      else if (node.parentNode instanceof Node) {
        entry +=
          "[" +
          Math.max(
            0,
            Array.prototype.indexOf.call(
              node.parentNode.children || node.parentNode.childNodes,
              node
            )
          ) +
          "]";
      }

      path.push(entry);

      if (dontGoUpTheDom === true) {
        break;
      }

      // go up the DOM
      node = node && node.parentNode;
    }

    return path.length > 0 ? path.reverse().join(" > ") : false;
  }
Returns "DOM path" to a given node (starting from <body> down to the node)

Example: body.logged_out.vis-public.env-production > div > div