How do you simulate clicks on elements? #83

Open
blazer82 opened this Issue Feb 5, 2014 · 4 comments

Projects

None yet

3 participants

@blazer82

After I found that jQuery's $.trigger() doesn't work I did some googling and came up with a function like this:

clickElement = function(document, el) {
    var ev = document.createEvent("MouseEvent");
    ev.initMouseEvent(
        "click",
        true /* bubble */, true /* cancelable */,
        window, null,
        0, 0, 0, 0, /* coordinates */
        false, false, false, false, /* modifier keys */
        0 /*left*/, null
    );
    el.dispatchEvent(ev);
}

Is this an issue? Am I doing something completely wrong here?
If there's no other way to do this then a function like this should probably be shipped with laika. What do you think?

@lalomartins

I'm struggling with a similar issue here (need to test a file upload widget), I'm thinking instead we should expose more of the Phantom API. @arunoda what do you think?

Basically on the ClientConnector constructor, store the Phantom page object as this.page instead of a local variable, then we could use the full Phantom API. The one argument against is keeping Laika independent of Phantom… but for true end-to-end testing you need a browser API.

(Funny timing you bring this up now, I was just writing that on a local branch!)

@blazer82

I like the idea of exposing phantom's page object...

@lalomartins

implemented in commit c78bae6, if this looks good to everyone I'll pull-request it

edit: I know this isn't “the github way”, I should just make the PR 😸 but I don't want to split the conversation into yet another thread just yet until we're more or less in agreement

@arunoda
Owner

actually there seems to have no good alternative to phantomjs yet. So I'm fine with exposing the page object.
make sure to expose it with _page, so it is indicator that this is a private. You can use it, if you are pretty sure about it.
How about using ._phantomPage instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment