Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you simulate clicks on elements? #83

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

How do you simulate clicks on elements? #83

blazer82 opened this issue Feb 5, 2014 · 4 comments

Comments

@blazer82
Copy link

blazer82 commented Feb 5, 2014

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
Copy link
Contributor

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
Copy link
Author

blazer82 commented Feb 5, 2014

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

@lalomartins
Copy link
Contributor

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
Copy link
Owner

arunoda commented Feb 6, 2014

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
Projects
None yet
Development

No branches or pull requests

3 participants