0

I'm trying to click on an element of the iframe (onpage).

I decided on the element "ablobcathungry" for now.

I can't seem to get it to work however, no click is executed.

Are there special tricks required for this ?

The frame loads perfectly, so thats not the issue ...

<html>
<body>
    <iframe id="my-iframe" src="https://app.box.com/s/j7i88s6jb4yyk4wmiti4tol8ejoikdhl/folder/189200124977#" style=" display:block; position: absolute; height: 100%; width: 100%" frameborder="0" ></iframe>

    <script>
        window.onload = function() {
            var myIframe = document.getElementById("myIframe");
            myIframe.onload = function() {
                var iframeDocument = myIframe.contentDocument || myIframe.contentWindow.document;
                var year2023 = iframeDocument.body.querySelector(":contains('ablobcathungry')");
                year2023.click();
            };
        };
    </script>
</body>
</html>

I also tried another approach utilizing positioning, which yields no click either

<body>
    <iframe id="myIframe" src="app.box.com/s/j7i88s6jb4yyk4wmiti4tol8ejoikdhl/folder/189200124977" style="width: 100%; height: 1000px;"></iframe>
    <script>
        window.addEventListener("load", function() {
            var iframe = document.getElementById("myIframe");
            iframe.addEventListener("load", function() {
                setTimeout(function() {
                    var x = iframe.contentWindow.innerWidth / 2;
                    var y = iframe.contentWindow.innerHeight / 2;   iframe.contentWindow.document.elementFromPoint(x, y).click();
                }, 8000);
            });
        });
    </script>
</body>
</html>
Rye
  • 49
  • 5
  • Does this answer your question? [Trigger a button click inside an iframe](https://stackoverflow.com/questions/27332339/trigger-a-button-click-inside-an-iframe) – Konrad May 29 '23 at 12:59
  • I'm looking for a mouseclick not neccessarily a buttonclick. Furthermore I want to click on specific text. – Rye May 29 '23 at 15:37
  • I'm pretty sure you can't click on anything in the cross-origin iframe – Konrad May 29 '23 at 19:50

0 Answers0