JSFiddle - React, Tailwind, and code Playground

HTML

<body>
<input id="" name="myinput" type="text" value="">
<p>first click on text field above then CLICK HERE and you will see xpath in text field above but how to get xpath from iframe, but how to get xpath when click somewhere in iframe</p>

    <iframe src="http://www.lipsum.com/" width="100%"></iframe>
</body>

JavaScript

<script type="text/javascript">
        $("li,p,h3").hover(
      function () {
              $(this).addClass('hover'); ;
      },
      function () {
              $(this).removeClass('hover');
      }
    );
    </script>
<style type="text/css">
.hover {background:#FFCC00}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
    function getXPath(node, path) {
        path = path || [];
        if(node.parentNode) {
          path = getXPath(node.parentNode, path);
        }

        if(node.previousSibling) {
          var count = 1;
          var sibling = node.previousSibling
          do {
            if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {count++;}
            sibling = sibling.previousSibling;
          } while(sibling);
          if(count == 1) {count = null;}
        } else if(node.nextSibling) {
          var sibling = node.nextSibling;
          do {
            if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {
              var count = 1;
              sibling = null;
            } else {
              var count = null;
              sibling = sibling.previousSibling;
            }
          } while(sibling);
        }

        if(node.nodeType == 1) {
          path.push(node.nodeName.toLowerCase() + (node.id ? "[@id='"+node.id+"']" : count > 0 ? "["+count+"]" : ''));
        }
        return path;
      };

</script>
<script type="text/javascript">
    
    $(document).ready(function () {
        var selectedtextbox;
$('input[name="myinput"]').focus(function(){selectedtextbox=$(this);});
        $('p, li, a, href').click(function () { 
           var xpath = getXPath(this);
            selectedtextbox.val(xpath)
        });
    });
</script>