1

I'm trying to simulate a click in a html page I have, but it only works after I click on Inspect element with the Chrome console

When I run the command in the console what I get is this

$('#toolbar-preview').click();
n.fn.init {context: document, selector: "#toolbar-preview"}

If I press inspect element the behaviour changes in

$('#toolbar-preview').click();
me.fn.init [a#toolbar-preview.link.icon-only]

and the buttons gets properly clicked from then on.

I'm not an expert at all in javascript so I don't know what the issue is about, is it maybe an initialization issue of the button?

EDIT I don't know If I'm analyzing correctly, I think that what gets called is this, got this from the analyzing feature:

var g = function(e, t) {
        return t = null == t ? e.length - 1 : +t,
        function() {
            for (var i = Math.max(arguments.length - t, 0), a = Array(i), n = 0; n < i; n++)
                a[n] = arguments[n + t];
            switch (t) {
            case 0:
                return e.call(this, a);
            case 1:
                return e.call(this, arguments[0], a);
            case 2:
                return e.call(this, arguments[0], arguments[1], a)
            }
            var o = Array(t + 1);
            for (n = 0; n < t; n++)
                o[n] = arguments[n];
            return o[t] = a,
            e.apply(this, o)
        }
    }

and

on: function(e, i, a, n) {
                function o(e) {
                    var n = e.target;
                    if (t(n).is(i))
                        a.call(n, e);
                    else
                        for (var o = t(n).parents(), r = 0; r < o.length; r++)
                            t(o[r]).is(i) && a.call(o[r], e)
                }
                var r, s, l = e.split(" ");
                for (r = 0; r < this.length; r++)
                    if ("function" == typeof i || !1 === i)
                        for ("function" == typeof i && (a = arguments[1],
                        n = arguments[2] || !1),
                        s = 0; s < l.length; s++)
                            this[r].addEventListener(l[s], a, n);
                    else
                        for (s = 0; s < l.length; s++)
                            this[r].dom7LiveListeners || (this[r].dom7LiveListeners = []),
                            this[r].dom7LiveListeners.push({
                                listener: a,
                                liveListener: o
                            }),
                            this[r].addEventListener(l[s], o, n);
                return this
            }

I found the lines above following from here enter image description here

EDIT2: What I was able to understand for my issue is that it is caused by not having access to the iframe of the page. When I inspect an element the iframe gets exposed and then I can use queries and such to run commands like click. Is there a way to properly access an element inside the iframe with js? I have tried a couple of things but to no avail:

frameRef.contentWindow //I have no function to search for elements like "getElementById('')"
frameRef.contentWindow.document//this is null
frameRef.contentDocument//this is null
3
  • What does the click handler do? Commented Jun 3, 2019 at 15:46
  • Show the code for the click handler. Commented Jun 3, 2019 at 16:02
  • Add clarifications to the question, not comments. Commented Jun 3, 2019 at 16:02

1 Answer 1

1

Try with :

$( document ).ready(function() {
    $('#toolbar-preview').click();
  });
Sign up to request clarification or add additional context in comments.

1 Comment

This has the same issue, only works after I have inspected the element once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.